My program has to convert a numeric score and assign a letter grade to it. Problem is when the score is outside the 1-100 interval is still shows "letter grade is: " at the end of the program. How do i fix that so it doesnt show up when the user enters a score that is not in the interval?
#include <iostream>
usingnamespace std;
int main ()
{
int score;
char letterGrade;
//ask user for a number between 1 and 100
cout<<"Please enter a number between 1-100 and press enter."<<endl;
cout<<" The program will then show you "<<endl;
cout<<"the letter grade that corresponds to that number."<<endl;
cin>>score;
if (score<0 || score >100)
{
cout<<"Test scores must be in interval 1-100. "<<endl;
cout<<"Please exit the program and run it again"<<endl;
}
elseif (score <60)
{
letterGrade = 'F';
}
elseif (score <70)
{
letterGrade = 'D';
}
elseif (score < 80)
{
letterGrade = 'C';
}
elseif (score < 90)
{
letterGrade = 'B';
}
elseif (score <=100)
{
letterGrade = 'A';
}
// display the output
cout<<"The letter grade is: " <<letterGrade<<endl;
system("pause");
return 0;
}
if (score<0 || score >100)
{
cout<<"Test scores must be in interval 1-100. "<<endl;
cout<<"Please exit the program and run it again"<<endl;
}
Should be :
1 2 3 4 5 6
if (score<0 || score >100)
{
cout<<"Test scores must be in interval 1-100. "<<endl;
cout<<"Please exit the program and run it again"<<endl;
return 0;
}