# How to calculate average grade of a student in C++?

In this article we will write a program to calculate the average grade of the student. Basically we will ask the user for the marks as input. By the total marks obtained we will find the percentage. If the percentage is greater than 85% then print grade A, if percentage is less than 85% and greater than 75% then print grade B, if percentage is less than 75 and greater than 50 then print grade C, if percentage is less than 50 and greater than 30 then print grade D and finally, if percentage is less than 30 then print FAIL.

# Algorithm

• Ask user for the number of subjects.

• Ask for marks in each subject.

• Calculate total marks.

• Divide total marks by number of subject to get the percentage

• 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

• Print the results to the console.

``````#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

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