Write a program to ask the user to input a value responding a score on a test. The value should be between 0 and 100 inclusive. Using the IF control structure to output a message containing the letter grade corresponding to the score using the following table.
Score Letter grade
0-40 F
41-55 D
56-70 C
71-85 B
86-100 A
#include <iostream>
using namespace std;
int main() {
int score;
cout << "Enter a test score: ";
cin >> score;
if (score > 100) {
cout << "The score should be less or equal 100" << endl;
}
else if (score > 85) {
cout << "Your grade is A" << endl;
}
else if (score > 70) {
cout << "Your grade is B" << endl;
}
else if (score > 55) {
cout << "Your grade is C" << endl;
}
else if (score > 40) {
cout << "Your grade is D" << endl;
}
else if (score >= 0) {
cout << "Your grade is F" << endl;
}
else {
cout << "The score should be great or equal 0" << endl;
}
return 0;
}
Comments
Leave a comment