Everything compiles, but after I input I just get an infinite loop. Is there something I can do differently to make it not loop?
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Program Description
// This program will calculate test results for
// a set of test scores.
int main()
{
// Variables
int score; // Score on test
float avg; // Average score on all tests
int gA; // Letter grade A
int gB; // Letter grade B
int gC; // Letter grade C
int gD; // Letter grade D
int gF; // Letter grade E
int count; // Number of tests total
int low; // Lowest test score
int high; // Highest test score
int sum; // Sum of all scores
sum = 0;
count = 0;
low = 999;
high = -999;
gA = gB = gC = gD = gF = 0;
// Describe the process to the user
cout << "\nThis program will calculate test ";
cout << "results for a set of test scores." << endl;
// Prompt the user and read the input
cout << "Enter a list of test scores with -999 ending the list." << endl;
while (score != -999)
{
sum = sum + score;
count = count + 1;
if (score >= 90)
gA + 1;
else if (score >= 80)
gB + 1;
else if (score >= 70)
gC + 1;
else if (score >= 60)
gD + 1;
else
gF + 1;
if (score > high)
high = score;
if (score < low)
low = score;
}
avg = sum/count;
// Output the results
cout << " A B C D F" << endl;
cout << "-- -- -- -- --" << endl;
cout << setw(1) << gA
<< setw(3) << gB
<< setw(3) << gC
<< setw(3) << gD
<< setw(3) << gF
<< endl;
cout << "Number of tests: " << count << endl;
cout << "Average score: " << avg << endl;
cout << "Low score: " << low << endl;
cout << "High score: " << high << endl;
return 0;
}