+ 1

Output is a mess of errors, what am I doing wrong?

#include <iostream> using namespace std; int main() { int age; cin >> age; switch (age) { case age < 20 && age > 12: cout << "Your age: " << age << "\nYou are a teenager"; case age < 13 && age > 0: cout << "Your age: " << age << "\nYou are a child"; case age > 19 && age < 50: cout << "Your age: " << age << "\nYou are a adult"; case age > 49: cout << "Your age: " << age << "\nYou are a Senior"; } return 0; }

6th Oct 2017, 12:55 AM
Shawn_Delaney
Shawn_Delaney - avatar
1 Answer
+ 3
have to replace switch case with if condition switch statement only check for the condition not Comparing them but if..else.. is the right structure to be used there but you can manage to use switch statement if you like just type switch(age){ case12: case 13: case 14: case 16: case 17: case 18: case 19: case 20: //you are a tea...... } if you can manage the above condition you can absolutely passe the errors
6th Oct 2017, 1:06 AM
Nura Programmer
Nura Programmer - avatar