number doesn't go through switch statment

Could someone tell me why when I run the program it doesn't go through the swtich statement?


#include <iostream>

using namespace

int main()
{
int number = 0;


cout << "Enter a number between 1 and 10\n";
cin >> number;

if (number < 1 || number > 10)
{
cout << "You did not enter a number between 1 and 10. Try again.";
cin >> number;
}

switch (number)
{
case '1': cout << "You entered roman numeral I";
break;
case '2': cout << "You entered roman numeral II";
break;
case '3': cout << "You entered roman numeral III";
break;
case '4': cout << "You entered roman numeral IV";
break;
case '5': cout << "You entered roman numeral V";
break;
case '6': cout << "You entered roman numeral VI";
break;
case '7': cout << "You entered roman numeral VII";
break;
case '8': cout << "You entered roman numeral VIII";
break;
case '9': cout << "You entered roman numeral IX";
break;
case '10': cout << "You entered roman numeral X";
break;
}

System ("pause");
return 0;
}
In the switch statement your testing ints, not chars so don't use '. Your statement should look like: case 1: cout << "You entered roman numeral I";

Another thing you have using namespace. Using namespace what? You should add std after it so it looks like: using namespace std;

Two other things to mention using System ("pause"); is bad practice and next time please use code tags, they are the <> button on the right side of the submission box.
Got it, great thank you.
Topic archived. No new replies allowed.