0

What is wrong with this code? I really don't get it...

include <iostream> using namespace std; int main() { int age; cin >> age; switch (age) { case (age<18): cout << "Too young"; break; case (age>=18 && age<=70): cout << "Adult"; break; case (age>70 && age<120): cout << "Senior"; break; default: cout <<"what the hell are u?"; } return 0; }

30th Oct 2016, 9:23 PM
Jean-Rémy Cano
Jean-Rémy Cano - avatar
5 ответов
+ 2
No. You can only use cases in a switch statement for a SPECIFIC value for age. For what you want to do, use if-else statments. if () { } else if () { } else { }
30th Oct 2016, 9:38 PM
Cohen Creber
Cohen Creber - avatar
+ 1
Yup, correct.
31st Oct 2016, 1:41 PM
Cohen Creber
Cohen Creber - avatar
0
when you use switch we put only the value after case for exemple case 18: cout << ;
30th Oct 2016, 11:33 PM
Youssouph Sagna
Youssouph Sagna - avatar
0
Ok thanks for your help! So to sum up: "case number" is equivalent to "if X == number" Right?
31st Oct 2016, 1:39 PM
Jean-Rémy Cano
Jean-Rémy Cano - avatar
0
yeah
31st Oct 2016, 1:43 PM
Youssouph Sagna
Youssouph Sagna - avatar