Help Me C++

Write your question here.

I declare
int age;

i want to accept input that is just 0+
but when i type a letter example a the code continue and proceed to the next statement which suppose to proceed to the else statement i made.

pls help me! thanks

[code]
int age;

cin>> age;

if ((age>=0)&&(age<=19))
{
cout<<"Juvenile"
}
else
{
cout<<"Invalid!";
}
return 0


Last edited on
The problem occurs because you are inputting a char into an int. You first if statement simply compares it to zero and nineteen but does nothing to check the type. To see if the inputted type is correct you need to see if cin has failed using cin.fail().

P.S. Please use code tags.
Topic archived. No new replies allowed.