0

why cant i use cin functions an input for age, ill post the program below

int age; cin>>age; if(age>=18){ cout<<"Adult"; else{ cout<<"Teenager"; } } if(age>0){ cout<<"Child"; else{ cout"something is wrong"; } } return 0; // would this work ?

23rd Oct 2016, 11:10 AM
Abhinav Gokllani
Abhinav Gokllani - avatar
2 Respostas
0
you have not closed the if statement.close it before starting else.
26th Oct 2016, 12:51 PM
Zaltan
Zaltan - avatar
0
Hi Abhinav, You should set the bracket of ages. example 18+ = adult 10 to 17 = teen 9 below = child here is my code, check this out: #include <iostream> using namespace std; int main() { int age; cin>>age; if(age>=18) { cout<<"Adult"; } else if(age>=10 && age<=17) { cout<<"Teenager"; } else { cout<<"Child"; } }
10th Jun 2017, 2:59 AM
angelito platon
angelito platon - avatar