create a program that will accept a student name, student grade and will display the name and its equivalent grade.
A nested if is needed to validate the range of grade from 0 to 100 only. Inputted grade outside the given range is invalid input and there’s no grade equivalent. Your program should use nested if to validate the grade input and use the if-else statement to validate the grade options. Your program should have an input part and a display part. In the input part, you will be asked to input student name and student grade. For the output part, you have to display the student’s name and grade as shown in the sample output. The grading system is shown below.
Grading System:
A
94-100
A-
90-93
B+
87-89
B
83-86
B-
80-82
C+
77-79
C
73-76
C-
70-72
D+
65-69
D
60-64
F
59 and below
#include<iostream>
#include<string>
using namespace std;
int main(){
string name;
int grade;
cout<<"Enter student's name: ";
getline(cin,name);
cout<<"Enter student's grade: ";
cin>>grade;
if(grade<0 || grade>100){
cout<<"\nInputted grade outside the given range is invalid input and there’s no grade equivalent.\n";
}else{
string letterGrade="";
//94-100
if (grade >= 94)
{
letterGrade= "A";
}
else
{
//90-93
if (grade >= 90 && grade <= 93)
{
letterGrade = "A-";
}
else
{
//87-89
if (grade >= 87 && grade <= 89)
{
letterGrade = "B+";
}
else
{
//83-86
if (grade >= 83 && grade <= 86)
{
letterGrade = "B";
}
else
{
//80-82
if (grade >= 80 && grade <= 82)
{
letterGrade = "B-";
}
else
{
//77-79
if (grade >= 77 && grade <= 79)
{
letterGrade = "C+";
}
else
{
//73-76
if (grade >= 73 && grade <= 76)
{
letterGrade = "C";
}
else
{
//70-72
if (grade >= 70 && grade <= 72)
{
letterGrade = "C-";
}
else
{
//65-69
if (grade >= 65 && grade <= 69)
{
letterGrade = "D+";
}
else
{
//60-64
if (grade >= 60 && grade <= 64)
{
letterGrade = "D";
}
else
{
letterGrade = 'F';
}
}
}
}
}
}
}
}
}
}
cout<<"The student's name: "<<name<<"\n";
cout<<"The student's grade: "<<letterGrade<<"\n";
}
system("pause");
return 0;
}
Comments
Leave a comment