c++ - Histogram program aid -


i bit stuck program, program read in set of results , construct histogram indicates how many marks in each decade i.e how many between 10-20 etc.

i have 2 problems

  1. how can edit code allow readexamresults store ones in range of 0 -100
  2. how can printhisto print * @ setw() dependant on decade each of results in. e.g. if entered 3,4,5,11,23 should show 3 * in <10 decade, 1 in 10-20 decade , 1 in 20-30 decade.

any appreciated.

code:

using namespace std;   void readexammarks(int exammarks[], int sizeofarray){  cout << "please enter set of exam marks see histogram for:" << endl; int x = 0; for( int idx = 0; idx < sizeofarray; idx++){      cin >> x;     exammarks[idx] = x; } }  void printexammarks(int exammarks[], int sizeofarray){  for(int x = 0; x < sizeofarray; x++){      cout << setw(5) << exammarks[x]; } cout << endl; }   void printhisto(int exammarks[], int sizeofarray){ system("cls");  for( int x = 0; x < 6; x++){ cout << setw(5) << "*" << endl; } }  int main()  { int exammarks[5];  readexammarks(exammarks, 5); printhisto(exammarks, 5); printexammarks(exammarks,5);   system("pause"); } 

how can edit code allow readexamresults store ones in range of 0 -100

i guess meant readexammarks rather readexamresults. if so, need add if statement check input value actuall in range [0..100]. have changed loop statement for while because want increase idx when valid number entered.

void readexammarks(int exammarks[], int sizeofarray) {      cout << "please enter set of exam marks see histogram for:" << endl;      int x = 0;      int idx = 0;      while(idx < sizeofarray)           cin >> x;           if((x >=0) && (x <= 100)){                exammarks[idx] = x;                idx++;           }           else                cout << "error: value must in range [0...100], please enter valid value\n";       } } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -