assigning a letter grade to a numeric score?

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?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 #include <iostream>
using namespace 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;
	}

	else if (score <60)
	{ 
		letterGrade = 'F';
	}
	else if (score <70)
	{
		letterGrade = 'D';
	}
	else if (score < 80)
	{
		letterGrade = 'C';
	}
	else if (score < 90)
	{
		letterGrade = 'B';
	}
	else if  (score <=100)
	{
		letterGrade = 'A';
	}  

	// display the output  
	cout<<"The letter grade is: " <<letterGrade<<endl;
	system("pause");
	return 0;
}
1
2
3
4
5
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;
	}
So simple! lol. Thank you so much!
Topic archived. No new replies allowed.