+ 1

Switch statement only works with number or does it also work with double,char,string ?

Switch statement

26th Jun 2019, 12:08 PM
The unknown 321
The unknown 321 - avatar
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
26th Jun 2019, 12:24 PM
Agent_I
Agent_I - avatar
+ 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; }
26th Jun 2019, 12:35 PM
Agent_I
Agent_I - avatar
0
Can you show me a code for char data type please ?
26th Jun 2019, 12:25 PM
The unknown 321
The unknown 321 - avatar