Logic: Grade of a Student Using Switch Case in C
Logic is very simple to Calculate Grade Using Switch Statement in C. Taking input from the user(Input should be between range given 0 to 100 Else program play with you), as we know the grading system so divides the Mark by 10 and put the case condition in the program See the below Explanation Step by step for better understanding.
Number to Student Grade Conversion Table
Below is the number to Grade Conversion Table that helps us to implement the logic for the C Program to Find Grade of a Student Using Switch Case.
Switch Case Grade Program in C Explanation
So first divide the mark by 10 so we can get a reminder and as you can see in the program we use case 4 to case 10. So if the remainder is between 4 to 10 our case performs the particular grade operation and displays the result See the Step By Step Example for each case that may be in this grade(Switch Case Grade Program in C) problem.
Grade Program Example
Case 1: If the user is over-smart then there is a condition that if the mark given by the user is greater than 100 then our program displays the message "Don't Be Smart Enter your Marks Between Limit" or else part of the program will be performed.
Enter the Mark:- 1000
Output:- Don't Be Smart Enter your Marks Between Limits.
Case 2: If the user is entering the marks between 0 to 100 and then the particular grade portion will be executed and display the output in the Console screen.
Enter the Mark:- 95
Output:-Your Grade Is: A or Excellent
Now perform the same operation for Grades B, C, D, E, E-- and F. and write a C Program to Find Grade of a Student Using Switch Case.
Case 3: If Enter marks are not fulfilled the requirement of the case then the program will perform the default case.
Enter the Mark: 25
Output: Your Grade Is: F or Fail
Required Knowledge: Format Specifiers, Switch Case.
C Program to Find Grade of a Student Using Switch Case
#include<stdio.h>
int main()
{
int marks;
/*C Program to Find Grade of a Student Using Switch Case*/
printf("\n-----------------------------------");
printf("\nEnter The Marks Between 0 To 100:");
printf("\nEnter The Mark: ");
scanf("%d", &marks);
if(marks>100)
{
/* Marks greater than 100 */
printf("\nDon't Be Smart Enter your Marks Between Limit\n");
}
else
{
switch(marks/10)
{
case 10 :
case 9 :
/* Marks between 90-100 */
printf("\n Your Grade is: A");
break;
case 8 :
/* Marks between 80-89 */
printf("\n Your Grade is: B" );
break;
case 7 :
/* Marks between 70-79 */
printf("\n Your Grade is: C" );
break;
case 6 :
/* Marks between 60-69 */
printf("\n Your Grade is: D" );
break;
case 5 :
/* Marks between 50-59 */
printf("\n Your Grade is: E" );
break;
case 4 :
/* Marks between 40-59 */
printf("\n Your Grade is: E--");
break;
default :
/* Marks less than 40 */
printf("\n You Grade is: F or Fail\n");
}
}
getch();
return 0;
}
New: Grade of a Student Using Switch Case Output
Below you can find the source code output of the C Program to Find the Grade of a Student Using Switch Case.
whithout header file how can you your program work successfully
ReplyDeleteLatest IDE's does not need headers
ReplyDeleteLike codeblocks
Che k it
Thanks Ankit Mishra
DeleteDoes it work?
ReplyDeleteIt's Working. Thanks for Visit
DeleteInstead of giving marks in input.. if I use grade in input like A and as output I want the marks limit 75-79. how can I found this type of output using codeblocks? plz help
ReplyDeleteThe problem said clearly using switch-case. But your solution is using if-else?
ReplyDeleteThanks for Comment This is why cause many people think they are smart, and they put marks upto 10000 and infinite. So if you Enter marks in subject is greater than 100 then the program will print a message. This is Just for Fun You Can remove and Modified.
DeleteKeep visiting Keep sharing
what is about 75 to 79 grade A- ?
ReplyDeleteHello,
DeleteYou can modify or you can add as many conditions you want. This a just an example of my College grading System so there is No grading between 75 to 79 but you can put a case for according to your Query or you can send me a Query through email so I can provide a Full solution with respect to your Query.
Thanks For comment Keep visit keep share and Keep Healthy
Savage bro.. the first if condition statement which says to stay in limit
ReplyDeleteWhy this is savage bro. This is because you are not able to get a simple code. This is a very simple problem in CPP "Grade Of Given Marks Using Switch Case". The First "IF" statement say stay in the limit cause, programmer like you think and they are smart so they enter a marks value greater than 100 ie 2000. Now take a deep breath and think about what will the output or grade of a student in this way you are going to get 1000%.
DeleteAs we know that maximum marks you can get 100. This is the reason behind that the condition.
I Think now your doubt in clear Good luck in your career. Thanks for visiting
I think you can change the message. am I right?
DeleteYes We can change, this is just a msg you can also change. Thanks for your comment
DeleteThanks for sharing a awesome and well explain program in C++, I am following your website in long time nd always found new and complete working code. Thanks for everything and showing your support to newbie or new programmers.
ReplyDeleteThanks for showing your support towards us. We try to make code well function and always try to solve and update a new as well as old code. Thanks again please share if you like our efforts.
DeleteI like the logic, If someone want to play with the program, he is not going to win. Thanks Bro. Happy Coding
ReplyDeleteSame Thing I like about this website They have a Good knowledge about the Programming Problems
Deletehttp://www.svvideshvidya.com/
ReplyDeletethis is great
ReplyDeleteWe all know this is a great website
DeleteThis is a perfect solution of this problem
ReplyDeleteif 91-100=A & 81-90=B;then what is the code for this
ReplyDeletewhat is the purpose of case 10:?
ReplyDeletesuppose student has 100 marks...
Deletehello sir,
ReplyDeletei m not able to execute this program in vs code. its showing error, pls suggest what should i do. i m a beginner in c.
regards
Write a program to find the grade of a student given his marks based on below:
ReplyDelete90-100 A
80-90 B
70-80 C
60-70 D
<70 F