1 2 3 4 5 6 7
|
cin >> points;
while (points != -1) // Everything other than 1 will pass.
{
total = total + points; // Why does this go here?
cin >> points;
// And not here? (total = total + points;)
}
| |
As said, the first input has already happened before the loop.
Furthermore, (and the version by
integralfx has the issue too) you want to:
1. get input
2. check the input
3. use valid input |
The order is important; you do not want to add the -1 to total. You do not want to count the -1 as a game.
You have inputs on lines 1 and 5.
Line 2 has the check.
Line 4 uses input and it does it after the check on line 2 (and only if input is valid).
Line 6 would use the input whether it is valid or not.
for each student:
1 2 3 4 5 6 7 8 9
|
double total = 0; // Initialize the accumulator.
for (int test = 1; test <= numTests; ++test)
{
double score;
cin >> score;
total += score;
}
average = total / numTests; // Why does this go here?
cout << average << ".\n\n"; // Why does this go here?
| |
Why does one compute and show data about a student after all input of that student has been received?
You cannot show earlier, for the average needs all the input.
You cannot show later, for you don't store data for every student separately.