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;
}
below line 2 you can add something like :
1
2
cout<<"Write your grade in a percentage (type -1 if you want to exit) : "<<endl;
cin>>x;

you are not prompting the user to enter "x" anywhere in your code.
We may not be seeing the crucial bit of your code where you input x: since you get some output grade it may be in a part that you haven't included above.

As noxBox implies, it needs to be within the do loop - his suggestion regarding the position is good.

Don't they give out marks below 60 in your university or school?
Topic archived. No new replies allowed.