printing numbers from an array

Im a bit confussed on how to print the numbers from inside my array. I know i have to use a for loop but when i run this some weird numbers pop up.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
float score;
float grade[5];

for (int i=0; i<5; i++)
{
	cout << "Enter 5 grade scores: " << endl;
	cin >> score;
	
	score += grade[i];
	cout << endl;
}

for(int i=0; i<5; i++)
{
	cout << "Your grades are " << grade[i] << endl;
	//confused on this part..
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
float grade[5];

for (int i=0; i<5; i++)
{
	cout << "\nEnter 5 grade scores: " << endl;
	cin >> grade[i];
}

cout << "Your grades are " ;
for(int i=0; i<5; i++)
{
	cout << grade[i] << ' ';
	//confused on this part..
}
cout << '\n' ;
In line 9 you are adding the the value (some random number) from grade[i] to score, you should rather replace lines 7-9 with:
cin>>grade[i];
and remove your line 1 (for neatness).
If you do not understand the code, please ask.
Last edited on
Thanks guys made it clear what i was doing wrong! T
Topic archived. No new replies allowed.