#include <iostream>
#include <iomanip>
usingnamespace std;
// This program displays the average of quiz scores. You may assume that each quiz score will be entered
// as an is an integer in the range [0, 10].
int main()
{
int count = 0, score, sum;
cout << "Enter quiz score (negative value to quit)? ";
cin >> score;
while (score > 0)
{
sum += score;
++count;
cout << "Enter quiz score (negative value to quit)? ";
cin >> score;
}
if (count = 0)
{
cout << "No average could be calculated." << endl;
}
else
{
double avg = static_cast<double>(sum) / count;
cout << fixed << setprecision(1);
cout << "The average is " << avg << endl;
}
return 0;
}
And it's not working, can you help me fix some bugs? I need it fixed by tomorrow.
Line 18 is wrong. It should sayif (count == 0) This is a common typo that your compiler should warn you about.
Also, on line 8, you should initialize sum to be zero. Better yet, put all those declarations on separate lines so it is clear. int count = 0, score, sum; becomes