while loop

Thanks I figure it out
Last edited on
Knowing that they will have to use 0 in second code to get out of loop just subtract 1 from ding right after the loop.

I believe the problem with your first code is you are asking the user to enter multiple characters "yes" or "no" but you are assigning them to a char with can only store one character. You could change it so they only must enter Y for yes or N for no.
Last edited on
1
2
3
    char input;
    cout << "Would you like to enter another test score?(yes or no): ";
    cin >> input;

while ( input == 'yes' )
A character can only hold a single letter. If you want multiple letters (a string), use std::string.
http://www.cplusplus.com/reference/string/string/

1
2
3
4
5
6
     if ( input < 0 || input > 100 )
        {
            cout << "Entered scores are invalid. Please try again," << endl;
            input='no';

        }

Typo?

1
2
3
4
if( average < 60)
{
	cout<<"Your average is an F."<<endl;
}

What if the average is a negative number?

sum = sum + math;
can be just sum += math;

while ( math != 0);
What if the user actually got 0 on the test?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    
    do
    {
        if ( math < 0 || math > 100 )
        {
            cout << "Entered scores are invalid. Please try again, or type 0 to stop " << endl;

        }

        sum = sum + math;
        ding++;
        cin >> math;

    }
    while ( math != 0);

Even if the user enters an invalid score, the score is added to sum and ding is incremented.
Last edited on
Topic archived. No new replies allowed.