can you have more than 1 if else statement in an if statement
ie.
if(x>=64)
{
cout << "you are dead.";
else if(x<=11)
cout << "you are young.";
else if(x<19 && x>=12)
cout << "you are a teen.";
else if(x<=63 && x>=20)
cout << "you are an adult.";
}
Printable View
can you have more than 1 if else statement in an if statement
ie.
if(x>=64)
{
cout << "you are dead.";
else if(x<=11)
cout << "you are young.";
else if(x<19 && x>=12)
cout << "you are a teen.";
else if(x<=63 && x>=20)
cout << "you are an adult.";
}
>can you have more than 1 if else statement in an if statement
Yes.
No. This is an illegal construct because every else must have a matching if. Because you placed the else statements inside the first if, it will not work. This will though:Code:if(x>=64)
{
cout << "you are dead.";
else if(x<=11)
cout << "you are young.";
else if(x<19 && x>=12)
cout << "you are a teen.";
else if(x<=63 && x>=20)
cout << "you are an adult.";
}
-PreludeCode:if(x>=64)
cout << "you are dead.";
else if(x<=11)
cout << "you are young.";
else if(x<19 && x>=12)
cout << "you are a teen.";
else if(x<=63 && x>=20)
cout << "you are an adult.";
thanks that really helped :cool: