We read your photo as:
How to write a C program to evaluate student grades using a switch statement and how to compile and improve it?
ScanSolve AI Answer
Step-by-step solution
4 stepsThis C program uses a switch statement to evaluate a student's grade. Here's how to compile it and some improvements for the code:
Compile the program.
To compile this C code, you'll need a C compiler (like GCC).
- Save the code in a file, for example,
grade_evaluator.c. - Open a terminal or command prompt.
- Navigate to the directory where you saved the file.
- Compile the program using the command:
gcc grade_evaluator.c -o grade_evaluator - Run the executable:
./grade_evaluator(orgrade_evaluator.exeon Windows).
- Save the code in a file, for example,
Correct typographical errors.
There are a few spelling mistakes in your
printfstatements:- Line 12:
printf("\nwell done!");should beprintf("\nWell done!"); - Line 18:
printf("\nFairel!");appears to be a typo. It should likely beprintf("\nFair!");orprintf("\nFail!"); - Line 30:
printf("\nInvalld Grade.");should beprintf("\nInvalid Grade.");
- Line 12:
Improve input handling.
To ensure
scanfcorrectly reads the character and doesn't pick up a leftover newline character from the input buffer, add a space before the%cformat specifier:- Line 6: Change
scanf("%c",&grade);toscanf(" %c",&grade);
- Line 6: Change
Handle case sensitivity.
Your
switchstatement only checks for uppercase grades ('A', 'B', etc.). If a user enters a lowercase letter (e.g., 'a'), it will fall into thedefaultcase. To make it case-insensitive, you can convert the input character to uppercase (or lowercase) usingtoupper()from the<ctype.h>library before theswitchstatement.- Add
#include <ctype.h>at the top of your file. - After
scanf(" %c",&grade);, addgrade = toupper(grade);
- Add
Still stuck on this one?
Ask a follow-up, and the answer starts from this question.
More Computer Science Questions

Handwritten Step-by-Step Solution
Get this as a handwritten image on WhatsApp — like a tutor wrote it for you.
Try on WhatsApp