Jun 28, 2013 at 6:12am Jun 28, 2013 at 6:12am UTC
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 Jun 28, 2013 at 6:13am Jun 28, 2013 at 6:13am UTC
Jun 28, 2013 at 6:17am Jun 28, 2013 at 6:17am UTC
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 Jun 28, 2013 at 6:17am Jun 28, 2013 at 6:17am UTC
Jun 28, 2013 at 6:25am Jun 28, 2013 at 6:25am UTC
Thanks guys made it clear what i was doing wrong! T