// This program uses an if/else if statement to assign a // letter grade (A, B, C, D, or F) to a numeric test score. #include using namespace std; int main() { int testScore; // To hold a numeric test score char grade; // To hold a letter grade // Get the numeric test score. cout << "Enter your numeric test score and I will\n"; cout << "tell you the letter grade you earned: "; cin >> testScore; if (testScore < 0 || testScore > 100) //Input validation { // An invalid score was entered. cout << testScore << " is an invalid score.\n"; cout << "Run the program again and enter a value\n"; cout << "in the range of 0 to 100.\n"; } else { // Determine the letter grade. if (testScore < 60) grade = 'F'; else if (testScore < 70) grade = 'D'; else if (testScore < 80) grade = 'C'; else if (testScore < 90) grade = 'B'; else if (testScore <= 100) grade = 'A'; // Display the letter grade. cout << "Your grade is " << grade << endl; } return 0; }