simple array prob.

hi
i am tryin to teach myself c++ there arent any classes offered at my school.

i am stumped on how to get the right output for this program. Your supposed to enter a score then it displays how many students got the particular score.

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
#include <iostream>

using namespace std;

void dStudents();

int main()
{
	dStudents();
	return 0;
}

void dStudents()
{
	int score[20] = {99, 80, 76, 99, 95, 63, 70, 79, 80, 95,
			88, 80, 85, 79, 75, 72, 93, 90, 87, 100};
	int total = 0;
	int enter = 0;
	int x = 0;

	cout << " Enter a Score " << endl;
	cin >> enter;

	
while(x < 20)
{
	
	???
	???
}

	cout << " There are " << total << " students that scored a " << enter << endl;

}

i dont know what to do to get the loop/counters to work. Everything i tried gave me big numbers
i am sure my code is very flawed but help is appreciated.
try a for loop instead

//search for scores
for (int x = 0; x < 20; x = x + 1)
if (score[x] == enter)
total = total + 1;
//end if
//end for
ug so it was that simple!

i was just confusing myself i guess. Thanks you
Topic archived. No new replies allowed.