### Array Problem.Can't find the result.

i am coding a program to let the user enter unspecified numbers of score until the user enter a negative number,the program will display the average of the scores and the number of scores which are above or equal to the average, and also the number of scores which are below the average.
i'm almost done.
but at last i can't find the number of scores which are above or equal to the average, and also the number of scores which are below the average.
 ``12345678910111213141516171819202122232425262728293031323334353637383940`` ``````#include #include #include using namespace std; int main () { const int NUM_SCORE = 100 ; int scores[NUM_SCORE]; int count; int sum=0; double average; for(count=0;count < NUM_SCORE;count++) { cout << "Enter score " << (count + 1) << ": "; cin >> scores[count]; sum += scores[count]; if(scores[count]<0) {break;} } int high=0; int low=0; average = sum/(count); for(count = 0;count <= NUM_SCORE;count++) { if(scores[count]>=average) {high++;} else {low++;} } cout << "The average of the scores is: " << fixed << setprecision(2) << average+1 << endl; cout << "The number of score(s) that are above or equal to the average: " << high << endl; cout << "The number of score(s) that are below the average: " << low << endl; return 0; } ``````
count contains the number of scores so use that instead of NUM_SCORE in the second loop (and change <= to <).
veeyik,

I’m very new to programming but, I fidgeted w/your code for a while and came to a conclusion I believe you were trying to reach. I did alter you code quite a bit but, hopefully the solution is helpful. I’m almost certain there are better / less altered solutions out there that I would also be interested in seeing.

Thanks,
Redd

 ``12345678910111213141516171819202122232425262728293031323334353637`` ``````#include using namespace std; int main () { cout << "Enter number of games followed: "; int NUM_SCORE; cin >> NUM_SCORE; int *scores; scores = new int [NUM_SCORE]; int count; double sum=0; double average; for(count=0;count < NUM_SCORE;count++) { cout << "Enter score " << (count+1) << ": "; cin >> scores[count]; sum += scores[count]; } int high =0; int low =0; average = sum/(NUM_SCORE); for (count =0; count < NUM_SCORE; count++) { if (scores [count] >=average) {high++;} else {low++;} } cout << "The average of the scores is: " << average << endl; cout << "The number of score(s) that are above or equal to the average: " << high << endl; cout << "The number of score(s) that are below the average: " << low << endl; delete [] scores; return 0; }``````
Topic archived. No new replies allowed.