+ 1

If-else problem

#include <iostream> using namespace std; int main() { int age =0; cout <<"enter your age here: "; cin >>age; if (age >=18) { if (age <50) { cout<<"young man"; } } else { if (age ==0) { cout<<"not borned yet"; } if (age <18) if (age >=14) { cout<<"semi young"; } if (age >0) if (age <14) { cout<<"still kid"; } if (age <0) { cout<<"null age"; } if (age >= 50) { cout<<"old man"; } } return 0; } everything works fine except the numbers over 50, where is the problem guys ??? thanks

2nd May 2018, 7:29 AM
AMANULLAH
AMANULLAH - avatar
6 odpowiedzi
+ 1
You put it behind if(age < 50) as else
2nd May 2018, 7:51 AM
Jonas Schröter
Jonas Schröter - avatar
+ 1
At the top, you check if age is 18+, but the >= 50 condition is placed in the else block of >= 18
2nd May 2018, 7:39 AM
Jonas Schröter
Jonas Schröter - avatar
+ 1
Jonas Schröter I their i have limited the age range from 18+ to 50 and in else block i choose from 50+
2nd May 2018, 7:45 AM
AMANULLAH
AMANULLAH - avatar
+ 1
Well at the top, there's if(age >= 18) but later there's else{ Here you check gor 50+. this cannot work
2nd May 2018, 7:48 AM
Jonas Schröter
Jonas Schröter - avatar
+ 1
Jonas Schröter what is the solution ? if i remove the else block which is >=50 still wont work
2nd May 2018, 7:50 AM
AMANULLAH
AMANULLAH - avatar
+ 1
Jonas Schröter wow it solved... thanks alot ❤❤❤
2nd May 2018, 7:55 AM
AMANULLAH
AMANULLAH - avatar