Switch statement not working! MUCH FRUSTRATION!

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
/*Write a program that asks the user to enter a number within the range of 1 through
  10. Use a switch statement to display the Roman numberal version of that number.*/

#include "stdafx.h"
#include <iostream> 

using namespace std; 

int main()
{
	int x; 

	cout << "Enter a number between 1 and 10: " << endl;
	cin >> x;
	while(x <= 0 || x > 10)
	{
		cout << "Please enter a number between 1 and 10" << endl;
		cin >> x; 
	}
	

	switch (x)
	{
	case '1': cout << "The Roman numeral version is: I"   << endl;
		break; 
	case '2': cout << "The Roman numeral version is: II"  << endl;
		break; 
	case '3': cout << "The Roman numeral version is: III" << endl;
		break;
	case '4': cout << "The Roman numeral version is: IV"  << endl;
		break; 
	case '5': cout << "The Roman numeral version is: V"   << endl;
		break; 
	case '6': cout << "The Roman numeral version is: VI"  << endl;
		break;
	case '7': cout << "The Roman numeral version is: VII" << endl;
		break;
	case '8': cout << "The Roman numeral version is: VIII"<< endl;
		break; 
	case '9': cout  << "The Roman numeral version is: IX" << endl;
		break; 
	case '10':cout << "The Roman numeral version is: X"   << endl;
	}
	return 0;

}



When I execute this program the result does not display a roman numeral but rather says press any key to continue, as if it skipped the switch statement altogether! I can't find any syntax problem or anything so please, help me!
1
2
3
case '1':
case 1:
//Etc 
character '1' != integer 1
closed account (1CfG1hU5)
while loop changes to work:

while (x >= 1 || x <= 10)
{
...
}

line 19, closing brace "}", move to 45.

the while loop must encompass the switch for the numbers chosen to work
while loop changes to work:


jt1, his while loop is fine, the OP is checking user input is valid there.
closed account (1CfG1hU5)
k
remove single quotation after case
closed account (1CfG1hU5)
entering '10' will cause case 1 to display. also char x is better than int x. program didn't work right for me at cpp.sh with int declaration.
Last edited on
Please, show me how to get 10 in a single char.
Only his problem was quotation marks around values. That it, nothing else have to change.
http://cpp.sh/3bm
http://ideone.com/4q9WJb
Topic archived. No new replies allowed.