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; }
4 ответов
+ 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.
+ 7
@Terry : You should not place the "15-59 if" inside "60-70 if".
+ 1
https://code.sololearn.com/cwS40x46jB9D/?ref=app
This an example without using the AND oprater.
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.