+ 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.😥
15 Respuestas
+ 8
Ravi Henry Can you show your attempt please?
https://www.sololearn.com/discuss/1316935/?ref=app
+ 3
In which language you tried ?
+ 3
Then go through the solo learn c++ course it will be easy to clear your concept.
+ 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";
}
+ 2
C++
+ 1
Sorry I haven't
+ 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;
}
+ 1
https://code.sololearn.com/cg0vYp7ljl73/?ref=app
hope u understand it.
+ 1
I got the answer punnam Ruthvik Reddy but I think the code that you have share that is for turbo c++
+ 1
Okey
Thx
0
I am writing again
0
Output is not coming old what is the error in code
0
Hellow yeva I have posted my attempt
0
It works on all the compilers which support c language
0
😋Anna it is due to the sololearn