+ 1
Switch question
How can l write this with the '' switch'' statement: int a; cin a; switch(a) case a>0: cout.... break; case a<0: cout... break; I want to replace the if statement, but the switch statement does not work because' a' is not a cobstant variable. Is there a way to write a unconstant variable in the 'case' row? PS:I want to use exactly the switch statement
3 Respuestas
+ 8
switch(a >= 0) {
case 1:
cout << (...);
break;
case 0:
cout << (...);
break;
}
+ 1
Partialy true. The case arguments must be constant, means no expression.