0

when I run this code am getting an error ,please help.why am getting an error at case(age<=age):

#include <iostream> using namespace std; int main() { int age = 4; switch (age) { case (age<=16): cout << "Too young"; break; case (age>=18): cout << "Adult"; break; case (age>=45): cout << "Senior"; break; } return 0; }

22nd Dec 2016, 10:06 AM
Hisani msigwa
Hisani msigwa - avatar
4 ответов
+ 1
case requires a constant expression. Which is to say, it's value has to be determined at compile time. So you shouldn't use variable expressions inside case column
22nd Dec 2016, 11:09 AM
Manikanta Nallamalli (Mittu)
Manikanta Nallamalli (Mittu) - avatar
0
These isn't full code. Please paste full code.
22nd Dec 2016, 10:10 AM
S M Sarwar
S M Sarwar - avatar
0
please help
22nd Dec 2016, 10:33 AM
Hisani msigwa
Hisani msigwa - avatar
0
you pass an int into the switch but then have bools in the cases, see the problem here?
22nd Dec 2016, 10:55 AM
johnnyBoy
johnnyBoy - avatar