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.";
}
This is a discussion on Really newbie question about if within the C++ Programming forums, part of the General Programming Boards category; can you have more than 1 if else statement in an if statement ie. if(x>=64) { cout << "you are ...
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.";
My best code is written with the delete key.
thanks that really helped![]()