Write a program that takes a grade (A, B, C, D, or F) as input and prints a corresponding message using a switch statement.
#include <stdio.h>
int main() {
// Declare variable
char grade;// Input: Get the grade from the user
printf(“Enter the grade (A, B, C, D, or F): “);
scanf(” %c”, &grade); // Note the space before %c to consume any previous newline character// Process and Output: Print corresponding message using a switch statement
switch (grade) {
case ‘A’:
case ‘a’:
printf(“Excellent! Keep up the good work.n”);
break;
case ‘B’:
case ‘b’:
printf(“Good job! You’re doing well.n”);
break;
case ‘C’:
case ‘c’:
printf(“Fair enough. Work harder for improvement.n”);
break;
case ‘D’:
case ‘d’:
printf(“You need to focus more. Seek help if needed.n”);
break;
case ‘F’:
case ‘f’:
printf(“Unfortunately, you’ve failed. Consider seeking help.n”);
break;
default:
printf(“Invalid grade entered. Please enter A, B, C, D, or F.n”);
return 1; // Exit the program with an error code
}return 0; // Exit the program successfully
}