- 1

Question from a complete beginner for a C++ program

#include <iostream> using namespace std; int main() { int age; cin >> age; if (age<=16) { cout << "Teenager" << endl; } if (age>=18) { cout << "Adult" << endl; if (age>=50) { cout << "Old" << endl; } } return 0; } Can someone provide a solution so that the console doesn't output both Adult and Old when we input values that are over fifty? My knowledge is quite shallow so I appreciate your guidance. Thanks!

26th Aug 2020, 7:14 AM
Riv iera
Riv iera - avatar
3 Answers
+ 1
Actully if you enter big Number which is more than 50 than in this case your both condition will be run and it will print Adult and old. U need to do some changes if(age>=18) Then cout<<"Adult"; else Then cout<<" old";
26th Aug 2020, 7:46 AM
đŸ’«AsđŸ’«
0
Thanks for the answers but in addition to the Else statements I also had to add another condition from (age>=18) to (age>=18; age<=49) to make the first line of code false
1st Sep 2020, 1:33 AM
Riv iera
Riv iera - avatar