codescracker


c++

C++ Program to Calculate Grade of Student



« Previous Program Next Program »


Calculate Grade of Student in C++

To calculate grade of a student on the basis of his total marks in C++ Programming, you have to ask to the user to enter marks obtained in some subjects (5 subjects here). To calculate grade of student, first calculate the mark's sum of all the subjects and then calculate average marks. Now start checking for the grades to display the result as shown here in the following program.

C++ Programming Code to Calculate Grade of Student

Following program ask to the user to enter the marks obtained in 5 subjects to calculate and display the grade of the student:

/* C++ Program - Calculate Grade of Student */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	int mark[5], i;
	float sum=0,avg;
	cout<<"Enter marks obtained in 5 subjects :";
	for(i=0; i<5; i++)
	{
		cin>>mark[i];
		sum=sum+mark[i];
	}
	avg=sum/5;
	cout<<"Your Grade is ";
	if(avg>80)
	{
		cout<<"A";
	}
	else if(avg>60 && avg<=80)
	{
		cout<<"B";
	}
	else if(avg>40 && avg<=60)
	{
		cout<<"C";
	}
	else
	{
		cout<<"D";
	}
	getch();
}

When the above C++ program is compile and executed, it will produce the following result:

C++ program student grade

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test