C++ Program to Calculate Grade of Student Using Switch Case

In this C++ program, we will calculate the grade of a student based on the total marks obtained by the student in five subjects. Here we will use a switch case statement, however you can write same program using if-else ladder statement also. Here is the range of Grades:

Marks >= 90 : Grade A
Marks >= 70 && < 90 : Grade B
Marks >= 50 && < 70 : Grade C
Marks < 50 : Grade D

We will first ask user to enter the marks of five subjects and calculate the total marks obtained by student. Then we will calculate the average marks by dividing total marks by 5. Now, we will use switch case statement to select the appropriate range for his average marks and print the grade accordingly.

C++ Program to Calculate Grade of Student Using Switch Statement

// C++ Program to calculate grade of student 
#include <iostream>
using namespace std;

int main() {
    int score, i, average;
    float total=0;
    cout<< "Enter marks of 5 subjects\n";
    for(i=0; i<5; i++) {
 cin >> score;
 total += score;
    average = total/5;
    cout<<"Grade : ";
    switch(average/10) {
       case 9 :
           cout << "A";
       case 8 :
       case 7 :
           cout << "B";
       case 6 :
       case 5 :
           cout << "C";
       default :
           cout << "D";  
    return 0;
Enter marks of 5 subjects
97 89 78 87 68
Grade : B

Recommended Posts
C++ Program to Make a Simple Calculator
C++ Program to Find All Square Roots of a Quadratic Equation
C++ Program to Check Leap Year
C++ Program to Calculate Average Percentage Marks
C++ Program to Find Sum of Natural Numbers
C++ Program to Swap Numbers in Cyclic Order
C++ Program to Find Average of Numbers Using Arrays
C++ Program to Find Size of Variables using sizeof Operator
C++ Program to Check Strings are Anagram or Not
C++ Program to Convert Fahrenheit to Celsius
C++ Program to Check for Armstrong Number
All C++ Programs