## jer_stud56

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;
}``````

## gerard4143 371

Try the break statment

## jer_stud56

Thanks worked perfectly haha.
It doesn't read the scores I put in though, is there a reason why?

## WaltP 2,905

Could it be there are no input statements in your code?

## atish00

gA + 1; should be gA ++ or gA = gA+1;

## atish00

you don't ahve te input astement ask user to input the scores.

example

for(i=0 ; a! == -999 ; i++)
{
cin>>score;
}

## prushik 50

you need an input statement inside your while loop.
Take the break statement out, it was an infinite loop because score can never = -999 because score never changes inside the loop.

## jer_stud56

wow I must be out of it...I can't imagine why I didn't realize I didn't put an input statement in.
Changed the gA,B,C,D,F according to atish00 and put an input statement in. Works without flaw now. Thanks everyone for your help.