# C++ Program to Calculate Grade of Student

## C++ Program to Calculate Grade of Student

Here we write a C++ program to find grade of student, If percentage is greater than 85% print A grade, If percentage is less than 85% print B grade, If percentage is less than 75 print C grade, If percentage is less than 50 print D grade, If percentage is less than 30 print fail."

### Algorithm to Calculate Grade of Student

• First Receive Student Marks of each subject.
• Calculate sum of all subjects marks.
• divide total marks by number of subject (percentage=total marks / number of subject).
• If percentage > 85 print A grade, If percentage < 85 && percentage >= 75 print B grade, If percentage < 75 && percentage >= 50 print C grade, If percentage > 30 && percentage <= 50 print D grade, If percentage <30 print fail
• Finally print percentage on screen.

## C++ Program to Calculate Grade of Student Using if else

```#include<iostream.h>
#include<conio.h>

void main()
{
int no, i;
float marks, per=0, total=0;
clrscr();
cout<<"Enter number of subject: ";
cin>>no;
cout<<"Enter marks of "<<no<<" subject: ";
for(i=0; i<no; i++)
{
cin>>marks[i];
}
for(i=0; i<no; i++)
{
total=total+marks[i];
}
per=total/no;
cout<<"Percentage: "<<per<<" %" <<endl;
if(per>85) {
}
else if(per<85 && per>=75)
{
}
else if(per<75 && per>=50)
{
}
else if(per<50 && per>=30)
{
}
else
{
cout<<"Fail";
}
getch();
}
```

## Output 1

```Enter number of subject: 6
Enter marks of 6 subject:
88
67
98
76
63
72
Percentage: 77.33 %
```

## Output 2

```Enter number of subject: 5
Enter marks of 5 subject:
77
87
95
83
92
Percentage: 86.80 %
```