+ 1
Switch statement only works with number or does it also work with double,char,string ?
Switch statement
3 Answers
+ 1
In C++, switch will only work with data types that hold integer value such as int, enum, char (char also holds integer value) and so on. It won't work with floating-point like float or double. It won't also work with string
+ 1
int main() {
char a = 'c';
switch(a) {
case 'a':
cout << "it's a";
break;
case 'b' :
cout << "it's b";
break;
case 'c':
cout << "it's c";
break;
default:
cout << "it's something else";
}
return 0;
}
0
Can you show me a code for char data type please ?