0

What's wrong with this code? I can't get it to print out adult. All the others work.

#include <iostream> using namespace std; int main() { int age; cin>>age; if (age<=15){ cout<<"too young";} else { if(age>60 && age<70){ if(age>15 && age<60){ cout << "adult"; } else { cout << "Senior"; } } } if(age>=70){ cout<<"Your an old timer";} return 0; }

22nd Nov 2017, 4:54 PM
Terry Smart
4 odpowiedzi
+ 8
if (age > 60 && age < 70) means age lies between 60 and 70. if (age > 15 && age < 60) means age lies between 15 and 60. You placed second "if" inside first "if". If first "if" is true, second "if" can never be true and that's why "adult" won't be printed in any situation.
22nd Nov 2017, 4:59 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 7
@Terry : You should not place the "15-59 if" inside "60-70 if".
22nd Nov 2017, 5:05 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 1
https://code.sololearn.com/cwS40x46jB9D/?ref=app This an example without using the AND oprater.
22nd Nov 2017, 7:20 PM
Ryan
Ryan - avatar
0
can y'all write it where it should be. I don't get it. I'm struggling with the if else commands and how they operate.
22nd Nov 2017, 5:07 PM
Terry Smart