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.
Please help this is the last step ;(
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <iomanip>
#include <cmath>
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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>

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.