Write a COMPLETE C++ to ask the user to enter a grade. If the grade is greater t
ID: 3806293 • Letter: W
Question
Write a COMPLETE C++ to ask the user to enter a grade. If the grade is greater than or equal to 60, but program to 100, the program will display "Congratulation! passed the exam." If the grade is less than 60, but greater than or equal to 0, program display "You failed the test. Work harder." If the grade is not within the range from 0 to 100 program will display "Invalid grade." The following is a sample running result: Running example 1: Please enter your grade: 89 Congratulation! You passed the exam. Press any key to continue .... Running example 2: Please enter your grade: 55 You failed the test. Work harder. Press any key to continue .... Running example 3: Please enter your grade: 105 Invalid grade. Press any key to continue ....Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int grade; // An integer variable grade
cout << "Please enter your grade:";
cin >> grade; // Reading grade
if(grade >= 0 && grade <= 59){
cout << "You failed the test. Work harder." << endl;
}else if(grade >= 60 && grade <= 100){
cout << "Congratulation! You passed the exam." << endl;
}else {
cout << "Invalid grade." << endl;
}
return 0;
}
/*
Output :-
Please enter your grade:89
Congratulation! You passed the exam.
Press any key to continue.........
Please enter your grade:55
You failed the test. Work harder.
Press any key to continue.........
Please enter your grade:105
Invalid grade.
Press any key to continue.........
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.