+ 2

What's wrong?!

#include <iostream> using namespace std; int main() { int age; cin>>age; cout<<"Please, introduce your age:"<<endl; if(65>age >= 18) { cout << "Adult"<<endl; } if(100>age>=65){ cout<<"Old man/lady"<<endl; } if(age==100){ cout<<"What a beautiful age!"<<endl; } if(age>100){ cout<<"You're so old!"<<endl; } if (age<14){ cout<<"=>Child"; } if (age<0){ cout<<"Cool, you're unborn!"; } }

9th Jul 2017, 6:28 AM
MintyNerdyPoodle
MintyNerdyPoodle - avatar
3 Answers
+ 21
#include <iostream> using namespace std; int main() { int age; cout<<"Please, introduce your age:"<<endl; cin>>age; if(age>= 18 && age<65) { cout << "Adult"<<endl; } else if(age>=65 && age <100){ cout<<"Old man/lady"<<endl; } else if(age==100){ cout<<"What a beautiful age!"<<endl; } else if(age>100){ cout<<"You're so old!"<<endl; } else if (age<14){ cout<<"=>Child"; } else if (age<0){ cout<<"Cool, you're unborn!"; } }
9th Jul 2017, 6:41 AM
Jobelle
Jobelle - avatar
9th Jul 2017, 6:57 AM
‎ ‏‏‎Anonymous Guy
0
In your first and second if - else you have two expressions but you try to make only one expression. the right way is to write if (65>age && age >=18) { ... }. And you should have a look at the if -else if - else statement. Its more readable because everyone can see that the diferent if statements be associated. Your last age doesn't make sense because nobody would write a negative number for his age.^^ And i am not sure but shouldn't the cout be before cin to show a message for the use what he has to do?! Hope I could help you. happy coding. :)
9th Jul 2017, 6:44 AM
Bumpety