Why doesn't VS recognise my input as an int? (it says that case i.e. '0' has datatype char?!)
int main() {
int slct;
cout << "\n\t\tWelcome to the Desert Jewel Casino\n" << endl;
cout << "Please enter your Choice:\n" << endl;
cout << "\n[Floor 0]" << endl;
cout << "\n[Floor 1]" << endl;
cout << "\n[Floor 2]" << endl;
cout << "\n[Floor 3]" << endl;
cout << "\n[Floor 4]" << endl;
cout << "\n[Floor 5]\n" << endl;
cin >> slct;
switch (slct) {
case '0' :
cout << "Welcome to the Groundfloor" << endl;
break;
case '1':
cout << "Floor: 1" << endl;
break;
case '2':
cout << "Floor: 2" << endl;
break;
case '3':
cout << "Floor: 3" << endl;
break;
case '4':
cout << "Floor: 4" << endl;
break;
case '5':
cout << "Floor: 5" << endl;
break;
default:
cout << "The selected Floor does not exist!" << endl;
}
return (0);
}
A character surrounded by single quotes ' is a character literal.
If you want the integer value you should write it without quotes.
Last edited on