Write a C++ program that asks the user for the student’s grade in percentage, and outputs the letter grade for it.

Write a C++ program that asks the user for the student’s grade in percentage, and outputs the letter grade for it. This process should be done continuously without exiting/closing the program, unless the user terminates the program by pressing -1

Hello, I have written the code for the part that reads the percentage and outputs a grade but I do not know how to have the code keep going and then stop if the user inputs a negative 1. My code right now just keeps repeating the output grade. Hope you can help!

do
{
if (x >= 95)
{
cout << "A" << endl;
}
if (x >= 90 && x <= 94)
{
cout << "A-" << endl;
}
if (x >= 87 && x <= 89)
{
cout << "B+" << endl;
}
if (x >= 83 && x <= 86)
{
cout << "B" << endl;
}
if (x >= 80 && x <= 82)
{
cout << "B-" << endl;
}
if (x >= 77 && x <= 79)
{
cout << "C+" << endl;
}
if (x >= 73 && x <= 76)
{
cout << "B" << endl;
}
if (x >= 70 && x <= 75)
{
cout << "C-" << endl;
}
if (x >= 67 && x <= 69)
{
cout << "D+" << endl;
}
if (x >= 63 && x <= 66)
{
cout << "D" << endl;
}
if (x >= 60 && x <= 62)
{
cout << "D-" << endl;
}

}
while (x != -1);

return 0;
}
Add a cin>>x statement at the beginning of your do-while loop
closed account (LA48b7Xj)
Are you sure? The cin >> x should be at the start of the do while like this

1
2
3
4
5
6
7
8
int x;
do    
{
    cin >> x;

    /* if statements */

} while (x != -1);
Last edited on
Topic archived. No new replies allowed.