#include <iostream>
using namespace std;
int main() {
int number;
cout << "Please enter a number <1-50>:";
cin >> number;
switch(number) {
case'1':
cout << "one" << endl;
break;
}
system("PAUSE");
return EXIT_SUCCESS;
}
the program can run
but cannot show the statement when I input 1
why???
You mean case 1:
(without the single quotes) since '1' != 1 because
'1' is a char whose (ASCII) value is 0x31 and 1 is an integer whose value is 1.
Although somehow I don't think this is how you are supposed to solve the problem
unless your switch statement is going to have 4+ billion cases.
case 1,just get rid of the single quotation marks .The "number" is a int.Or you can change it to char,continue to have the single quotation marks.
thanks you for your answer
i know what i'm wrong now^^