If-else problem | Sololearn: Learn to code for FREE!

+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

5/2/2018 7:29:07 AM

AMANULLAH

6 Answers

New Answer

+1

You put it behind if(age < 50) as else

+1

At the top, you check if age is 18+, but the >= 50 condition is placed in the else block of >= 18

+1

Jonas Schröter I their i have limited the age range from 18+ to 50 and in else block i choose from 50+

+1

Well at the top, there's if(age >= 18) but later there's else{ Here you check gor 50+. this cannot work

+1

Jonas Schröter what is the solution ? if i remove the else block which is >=50 still wont work

+1

Jonas Schröter wow it solved... thanks alot ❤❤❤