C Program to Read a Grade and Display the Equivalent Description

This C program reads a grade and displays its equivalent description.

Problem Description

This program takes a grade as input and displays its equivalent description.

Problem Solution

1. Take the grade as input.
2. Use switch statement to verify the grade.
3. Print the output and exit.

Program/Source Code

Here is source code of the C program to read a grade & display the equivalent description. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C Program to accept a grade and declare the equivalent description
  3.  * if code is S, then print SUPER
  4.  * if code is A, then print VERY GOOD
  5.  * if code is B, then print FAIR
  6.  * if code is Y, then print ABSENT
  7.  * if code is F, then print FAILS
  8.  */
  9. #include <stdio.h>
  10. #include <ctype.h>
  11. #include <string.h>
  12.  
  13. void main()
  14. {
  15.     char remark[15];
  16.     char grade;
  17.  
  18.     printf("Enter the grade \n");
  19.     scanf("%c", &grade);
  20.     /*  lower case letter to upper case */
  21.     grade = toupper(grade);
  22.     switch(grade)
  23.     {
  24.     case 'S':
  25.         strcpy(remark, " SUPER");
  26.         break;
  27.     case 'A':
  28.         strcpy(remark, " VERY GOOD");
  29.         break;
  30.     case 'B':
  31.         strcpy(remark, " FAIR");
  32.         break;
  33.     case 'Y':
  34.         strcpy(remark, " ABSENT");
  35.         break;
  36.     case 'F':
  37.         strcpy(remark, " FAILS");
  38.         break;
  39.     default :
  40.         strcpy(remark, "ERROR IN GRADE \n");
  41.         break;
  42.     }
  43.     printf("RESULT  : %s\n", remark);
  44. }
Program Explanation

1. Take the letter as input and store it in the variable grade.
2. Convert the input letter into its uppercase using function toupper().
3. Using switch statement, verify the input letter.
4. If the letter is S, then copy the string ” SUPER” into the variable remark and break.
5. If the letter is A, then copy the string ” VERY GOOD” into the variable remark and break.
6. If the letter is B, then copy the string ” FAIR” into the variable remark and break.
7. If the letter is Y, then copy the string ” ABSENT” into the variable remark and break.
8. If the letter is F , then copy the string ” FAILS” into the variable remark and break.
9. In the default case, copy the string ” ERROR IN GRADE” into the variable remark and break.
10. Print the variable remark as output and exit.

advertisement
advertisement
Runtime Test Cases
 
Enter the grade
s
RESULT  :  SUPER
 
Enter the grade
a
RESULT  :  VERY GOOD
 
Enter the grade
b
RESULT  :  FAIR
 
Enter the grade
y
RESULT  :  ABSENT
 
Enter the grade
f
RESULT  :  FAILS

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Books in C Programming, Data-Structures and Algorithms

Note: Join free Sanfoundry classes at Telegram or Youtube
If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics of C, go to C Programming Examples.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.