Switch Statement Closing Out Program

Hello everyone!

My program is not doing what it should be doing, and I am at a lost as to how to repair it.

This is not a homework assignment of any kind, nor is there timeline to have this answered by. This is just me doing some simple programming.

This is my program:
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
// 
// Using the switch statement to implement a sequence of parallel alternatives
// Using a switch statement to select a range of scores

#include<iostream>

using namespace std;

int main()
{
	int score;

	cout << "Enter your test score: "; 
	cin >> score;
	
	switch (score/10)
	{	case '10': 
	break;
		case '9': cout << "Your grade is an A." << endl;
		break;
		case '8': cout << "Your grade is an B." << endl;
		break;
		case '7': cout << "Your grade is an C." << endl;
		break;
		case '6': cout << "Your grade is a D." << endl;
		break;
		case '5':
			break;
		case '4': 
			break;
		case '3': 
			break;
		case '2': 
			break;
		case '1': 
		break;
		case '0' :
		cout << "Your grade is an F." << endl;
			break;
		default: cout << "Error: score is out of range.\n";

			system("pause");

			return 0;
	}
	cout << "Good-bye." << endl;
}


My program does not return the grade, and it just shuts down after inputting a numerical score. Any ideas as to how to fix this?
Your switch statement checks for chars not ints. Just remove the single quotes (' ') from your numbers. You should also move the return statement to the end of the program.
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
// 
// Using the switch statement to implement a sequence of parallel alternatives
// Using a switch statement to select a range of scores

#include<iostream>

using namespace std;

int main()
{
	int score;

	cout << "Enter your test score: "; 
	cin >> score;
	
	switch (score/10)
	{	case '10': 
	break;
		case 9: cout << "Your grade is an A." << endl;
		break;
		case 8: cout << "Your grade is an B." << endl;
		break;
		case 7: cout << "Your grade is an C." << endl;
		break;
		case 6: cout << "Your grade is a D." << endl;
		break;
		case 5:
			break;
		case 4: 
			break;
		case 3: 
			break;
		case 2: 
			break;
		case 1: 
		break;
		case 0 :
		cout << "Your grade is an F." << endl;
			break;
		default: cout << "Error: score is out of range.\n";

			
	}
	cout << "Good-bye." << endl;
	
	system("PAUSE");

			return 0;
}
Thanks a lot!

Worked like a charm!
Last edited on
Topic archived. No new replies allowed.