Program To Find Grade of Student in C++ Using IF…ELSE Statement
This Program is made to find grade of student in C++. User is required to input marks obtained and then program gives him a grade according to his marks. The grading scale is shown below:
Recommended reading: Find Sum of Digits of A Number in C++
Code To Find Grade of Student in C++:
using namespace std;
cout<<"---Program To Find Grade---"<<endl;
cout<<"Enter Marks: ";
if(marks>=90 && marks<=100)
cout<<"Your Grade is A+.";
else if(marks>=80 && marks<90)
cout<<"Your Grade is A.";
else if(marks>=70 && marks<80)
cout<<"Your Grade is B.";
else if(marks>=60 && marks<70)
cout<<"Your Grade is C.";
else if(marks>=50 && marks<60)
cout<<"Your Grade is D.";
else if(marks>=0 && marks<50)
cout<<"Your Grade is F.";
First we declared a variable named marks to take input from user.
After receiving input, this variable is tested using IF…ELSE statement.
Because we want to check number between two ranges, So we used And operator ( && ) to combine the conditions.
The true block of a particular executes only if both conditions are true. For example if user inputs number 98 then first IF block becomes true because this number is greater than 90 and less then 100. So Program will print “Your Grade is A+.” without quotations.
If marks are greater than 100 then program will print error message saying “Invalid input.”.
Recommended reading: Tower Of Hanoi Using Stacks in C++
I hope now you can write C++ program to calculate grade of student using IF…ELSE statement.
If you have any question then you can ask me in comments. I would like to answer them.
You can also Click Here To Download Exercise Files.