+ 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

9th May 2019, 7:47 PM
Филип Пилчевић (Filip Pilcevic)
Филип Пилчевић (Filip Pilcevic) - avatar
3 Respuestas
+ 8
switch(a >= 0) { case 1: cout << (...); break; case 0: cout << (...); break; }
9th May 2019, 7:55 PM
Anna
Anna - avatar
+ 1
Partialy true. The case arguments must be constant, means no expression.
10th May 2019, 7:41 AM
Daniel Adam
Daniel Adam - avatar