+ 2

Switch cases should be an integer?

GNU/GCC debugger print "switch not an integer".

27th Oct 2016, 2:42 PM
Adam Permana
Adam Permana - avatar
5 Respostas
+ 2
Integer is allowed char also allowed
27th Oct 2016, 6:49 PM
Shad Ahmad Zaidi
Shad Ahmad Zaidi - avatar
+ 2
@Pamir You can't use strings or floats in switch statements.
27th Oct 2016, 7:10 PM
Cohen Creber
Cohen Creber - avatar
+ 2
I want use switch for strings too
13th Nov 2016, 2:34 AM
-Diamond Armor -
-Diamond Armor - - avatar
+ 1
Jop, only integers (int, long, char unsigned int etc allowed). Or enums... but they are basically integer.
27th Oct 2016, 2:54 PM
Stefan
Stefan - avatar
0
use switch-case like: -psuedo code- int c; //it is for switch controller switch(c){ //switch using case 1:{ //case 1 for ( if (c == 1) ) //operations break; } case 2:{ //case 2 for ( if (c == 2) ) //operations break; } ...//so goes-on default:{ //case default for if none of the cases match //operations break; } } edit 1: you can use: -integers, -char, -string, -float, -basically every primitive data types. edit 2: @Cohen is right, i was wrong. I tried string, float, double and it gives me error. Still you can use integer and char.
27th Oct 2016, 6:48 PM
Pamir Ünsal
Pamir Ünsal - avatar