a.Write, compile, and run a a c++ program that accept a grade. The program shoul
ID: 3646013 • Letter: A
Question
a.Write, compile, and run a a c++ program that accept a grade. The program should requests a grade continuously as long as an invalid grade is entered. An invalid grade is any grade less than 0 or greater than 100. After a valid grade has been entered, your program should display the value of the grade entered.b. modify the program written for Exercise (a) so that the user is alerted when an invalid grade has been entered.
c. Modify the program written for Exercise (b) so that it allows the user to exit the program by entering the number 999.
d. Modify the program written for Exercise (b) so that it automatically terminates after five invalid grades are entered.
*********************************************************************************
#include <iostream>
using namespace std;
int main()
{
int grade;
cout << " Enter 999 to exit the program ";
do
{
cout << " Enter a grade from 0 to 100: ";
cin >> grade;
if (grade < 0 || grade > 100)
{
if (grade == 999)
{
break;
}
else
{
cout << " You entered an invalid # please enter a # from 0 to 100" << endl;
cin >> grade;
}
}
else
{
cout << "You entered : "<<grade<< endl;
}
} while (1);
return 0;
}
Explanation / Answer
#include using namespace std; int main() { int grade; int count; // to check the number of invalid grades entered count = 0; // initialisrion cout grade; if (grade < 0 || grade > 100) { if (grade == 999) { break; } else { coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.