### Histogram Array!

hey so I have an almost complete program that asks for test scores all entered on the same line and a sentinel value of -1 after the last score is entered your suppose to only accept 0-100 scores i only have two problems my histogram function returns zero if no values are entered and its suppose to return 1 and also i need it to return if the number of scores is greater than zero please help this is the code
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150`` `````` #include using std::cin; using std::cout; using std::endl; #include int readArray(int,int[]); int avg(int, const int[]); int stat(int, const int[], int&,int&,int&); int histogram(int,const int[],int[]); int main() { const int MAX_SCORE = 50; //the maximum # of scores that a user can enter int score[MAX_SCORE]; //create storage for up to 50 scores int nScores = readArray(MAX_SCORE, score); //read array and return count int avgScore; int minScore; int maxScore; if (stat(nScores, score, avgScore, minScore, maxScore) == 0) { cout << "The number of scores entered is: " << nScores << endl; cout << "The average of the data entered is: " << avgScore << endl << "The maximum score entered is: " << maxScore << endl << "The minimum score entered is: " << minScore << endl; int grade[5] = {0}; //={} is for newer compilers only histogram(nScores, score, grade); cout << "As: " << grade[0] << endl; cout << "Bs: " << grade[1] << endl; cout << "Cs: " << grade[2] << endl; cout << "Ds: " << grade[3] << endl; cout << "Fs: " << grade[4] << endl; } else cout << "no data" << endl; } int readArray(int n,int accepted[]) { char scores[100]; cout << endl; //prompt user for input cout << "Enter up to 50 test scores (0-100) after last score enter -1 to end: " << endl; int scoresEntered = 0; //read the scores from the keyboard, space and/or newline delimited for (int i = 0; i < n; i++) { cin >> scores; cin.ignore(0, ' '); int entered = atoi(scores); accepted[i] = entered; if(accepted[i] < 0 && accepted[i] <= 100) break; else scoresEntered++; } return scoresEntered; } int avg(int n,const int accepted[]) { int total = 0; if(n == 0) { return 0; } for(int i = 0;i < n; i++) { total = total + accepted[i]; } return total / n; } int stat(int n,const int accepted[],int& avgs,int& min,int& max) { if(accepted[0] < 0) { return 1; } if(n == 0) { return 0; } avgs = avg(n, accepted); min = accepted[0]; max = accepted[0]; for(int i = 0;i < n;i++) { if(accepted[i] < min) { min = accepted[i]; } if(accepted[i] > max) { max = accepted[i]; } } return 0; } int histogram(int nScores, const int accepted[], int letterGrade[]) { if(accepted[0] < 0) { return 1; } if(nScores == 0) { return 0; } for(int i = 0; i < nScores; i++) { if(accepted[i] >= 90) { letterGrade[0]++; } else if(accepted[i] >= 80 && accepted[i] <= 89) { letterGrade[1]++; } else if(accepted[i] >= 70 && accepted[i] <= 79) { letterGrade[2]++; } else if(accepted[i] >= 60 && accepted[i] <= 69) { letterGrade[3]++; } else if(accepted[i] < 50) { letterGrade[4]++; } } }``````
Topic archived. No new replies allowed.