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; }
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
{
}
+ 1
Yup, correct.
0
when you use switch we put only the value after case
for exemple
case 18:
cout << ;
0
Ok thanks for your help! So to sum up:
"case number" is equivalent to "if X == number"
Right?
0
yeah