+ 1

I want a code to clear my concept of if and else.

Output should depend on that condition:- 1.If age is equal to 0 then someting is wrong. 2.if age is smaller than 14 and greater than 0 then it should print child. 3.if age is larger than 14 and smaller than 17 then it should print teenager. 4.if age is greater than 18 and smaller than 60 then it should print adult. 5.if age is greater than 60 then it should print old. I have tried but haven't got success.😥

21st May 2019, 9:12 AM
Ravi Henry
Ravi Henry - avatar
15 Antworten
21st May 2019, 9:53 AM
Anna
Anna - avatar
+ 3
In which language you tried ?
21st May 2019, 9:13 AM
Abhinav
+ 3
Then go through the solo learn c++ course it will be easy to clear your concept.
21st May 2019, 12:10 PM
Abhinav
+ 3
You're thinking too complicated int age{74}; if(age <= 0) { std::cout << "something is wrong"; } else if(age < 14) { std::cout << "child"; } else if(age < 18) { std::cout << "teenager"; } else if(age < 60) { std::cout << "adult"; } else { std::cout << "old"; }
21st May 2019, 3:31 PM
Anna
Anna - avatar
+ 2
C++
21st May 2019, 9:14 AM
Ravi Henry
Ravi Henry - avatar
+ 1
Sorry I haven't
21st May 2019, 2:00 PM
Ravi Henry
Ravi Henry - avatar
+ 1
#include <iostream> using namespace std; int main() { int age = 74; if (age > 14) { if(age >= 18) { cout << "Adult"; } else { cout << "Teenager"; } } else { if (age > 0) { if (age >= 60) { cout << "old "; } else { cout << "Something's wrong"; } } } return 0; }
21st May 2019, 2:08 PM
Ravi Henry
Ravi Henry - avatar
21st May 2019, 3:09 PM
Punnam Ruthvik Reddy
+ 1
I got the answer punnam Ruthvik Reddy but I think the code that you have share that is for turbo c++
21st May 2019, 3:19 PM
Ravi Henry
Ravi Henry - avatar
+ 1
Okey Thx
21st May 2019, 3:23 PM
Ravi Henry
Ravi Henry - avatar
0
I am writing again
21st May 2019, 2:01 PM
Ravi Henry
Ravi Henry - avatar
0
Output is not coming old what is the error in code
21st May 2019, 2:09 PM
Ravi Henry
Ravi Henry - avatar
0
Hellow yeva I have posted my attempt
21st May 2019, 2:11 PM
Ravi Henry
Ravi Henry - avatar
0
It works on all the compilers which support c language
21st May 2019, 3:22 PM
Punnam Ruthvik Reddy
0
😋Anna it is due to the sololearn
22nd May 2019, 3:28 PM
Ravi Henry
Ravi Henry - avatar