05/03/2023

C++ Program to Display Grade of a Student Using Switch Case

Write a C++ Program to Find a Grade of Given Marks Using Switch Case, Take User Input and Print the Grade of a Student, Using an Absolute Grading System. Program in c++ language to find a grade of given marks using switch case. Take input from the user and print the grade of a student of the subject, for this problem use an absolute grading system, not a relative grading system. In the console also print the message with a grade to appreciate a student.

Logic is very simple for grade programs in C++ using a switch case. Taking input from the user(Input should be between the range given 0 to 100. Else program plays with you), as we know the grading system so divides the Mark by 10 and put the case condition in program See the below Explanation Step by step for better understanding.

Read: Java Program to Find the Grade of a Student Using Switch Case

C++ Program to Display Grade of a Student Using Switch Case



#
include <iostream>
using namespace std; int main() { /*Grade of Given Marks Using Switch Case in C++ */ int marks; while (1) { cout << "\n========================================="; cout << "\nEnter The Marks Between 0 To 100:"; cout << "\n=========================================\n"; cout << "\nEnter The Mark: "; cin >> marks; if (marks > 100) { /*Marks greater than 100 */ cout << "\nDon't Be Smart Enter your Marks Between Limit\n"; } else { switch (marks / 10) { case 10: case 9: /*Marks between 90-100 */ cout << "\n============================="; cout << "\nYour Grade Is: A or Excellent"; cout << "\n============================="; break; case 8: case 7: /*Marks between 70-89 */ cout << "\n============================="; cout << "\nYour Grade Is: B or Very Good"; cout << "\n============================="; break; case 6: /*Marks between 60-69 */ cout << "\n========================"; cout << "\nYour Grade Is: C or Fair"; cout << "\n========================"; break; case 5: case 4: /*Marks between 40-59 */ cout << "\n========================"; cout << "\nYour Grade Is: D or Pass"; cout << "\n========================"; break; default: /*Marks less than 40 */ cout << "\n================================================"; cout << "\nYou Grade Is: F or Fail\n"; cout << "\nSuggestion: Do Not show your Sheet to Your Parent"; cout << "\n================================================"; } } } return 0; }

Read: C Program to Find the Grade of a Student Using Switch Case

Grade of a Student 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 problem.

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 perform the Else part.

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

This operation performs the same for grades B, C, and D.

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

Also, see the program suggestion "Do Not show your Sheet to Your Parent"

The Output of Program to Display the Grade of a Student


The Output of Program to Display Grade of a Student

Similar to the Grade of a Student


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: