+ 3

How to make this code work without an error ?

https://code.sololearn.com/cCtT75U0mDQy/?ref=app

3rd Mar 2022, 1:02 PM
Norhan El-zomor
Norhan El-zomor - avatar
6 Answers
+ 2
#include <iostream> using namespace std; int main() { int age ; cin >> age ; if( age < 12){ cout << "You are a child "<< endl ; }else if( (age >= 12) && (age < 18)){ cout << "You are a teenager " << endl ; }else if((age >= 18) && (age < 60)){ cout << "You are an adult " << endl ; }else if( age >= 60 ){ cout << " You are a senior " << endl ; } return 0; }
3rd Mar 2022, 1:07 PM
Domonkos Gyömörey
Domonkos Gyömörey - avatar
+ 2
I never knew that switch shouldn't be used with expressions That is all I needed to know , Thanks alot 😊
3rd Mar 2022, 1:30 PM
Norhan El-zomor
Norhan El-zomor - avatar
+ 2
You may try something like this instead https://code.sololearn.com/cjAKzl7ym2JD/?ref=app
3rd Mar 2022, 1:32 PM
Simba
Simba - avatar
+ 2
Oh my god Simba that's so smart thank you
4th Mar 2022, 10:58 AM
Norhan El-zomor
Norhan El-zomor - avatar
+ 1
I think its simpler like this
3rd Mar 2022, 1:07 PM
Domonkos Gyömörey
Domonkos Gyömörey - avatar
+ 1
In switch you mustn't write expression, you only write a constants number after case keyword
3rd Mar 2022, 1:09 PM
Domonkos Gyömörey
Domonkos Gyömörey - avatar