Grade calculator
The below mentioned example calculates and displays the grade depending on the given marks.
Code
#include "stdafx.h"
#include "iostream"
#include "conio.h"
using namespace std;
int main()
{
float marks=0.0;
char grade[3];
char subject[35];
float gpa=0.0;
cout<<"ENTER THE NAME OF THE SUBJECT > ";
gets(subject);
cout<<"ENTER THE MARKS FOR YOUR GRADE CALCULATION > ";
cin>>marks;
if(marks<0|marks>100)
cerr<<"MARKS NOT IN RANGE (0-100)"<<endl;
else if(marks>=0&marks<=100)
{
if(marks>=90)
{
strcpy(grade,"A+");
gpa=4.0;
}
else if((marks>=85)&(marks<=89))
{
strcpy(grade,"A");
gpa=3.7;
}
else if((marks>=80)&(marks<=84))
{
strcpy(grade,"B+");
gpa=3.3;
}
else if((marks>=75)&(marks<=79))
{
strcpy(grade,"B");
gpa=3.0;
}
else if((marks>=70)&(marks<=74))
{
strcpy(grade,"B-");
gpa=2.7;
}
else if((marks>=65)&(marks<=69))
{
strcpy(grade,"C+");
gpa=2.3;
}
else if((marks>=60)&(marks<=64))
{
strcpy(grade,"C");
gpa=2.0;
}
else if((marks>=55)&(marks<=59))
{
strcpy(grade,"C-");
gpa=1.7;
}
else if((marks>=50)&(marks<=54))
{
strcpy(grade,"D");
gpa=1.0;
}
else
{
strcpy(grade,"F");
gpa=0.0;
}
cout<<"YOU GOT "<<grade<<" GRADE WITH "<<gpa<<" GPA IN "<<subject<<endl;
}
_getche();
return 0;
}
Output
ENTER THE NAME OF THE SUBJECT > Software engineering
ENTER THE MARKS FOR YOUR GRADE CALCULATION > 91
YOU GOT A+ GRADE WITH 4 GPA IN Software engineering