An if statement is NOT followed by a semicolon (i.e., ;
). If you wanna check whether tower_height
is greater than or equal to 0
AND less than or equal to 23
. Then you probably need to write something like
if (tower_height >= 0 && tower_height <= 23)
{
// do something
}
Notice that you must repeat tower_height
as it's regarded as a separate condition.
TheAll the code in the body of this if statement is executed if and only if both conditions are evaluated to true.
If an if statement doesn't have opening and closing curly braces, then only a single statement (specifically the one right after the statement) is executed when the condition is evaluated to true.
For example,
if (true)
// executed when the condition is evaluated to true
printf("hello from inside of the if statement!\n");
// executed anyway
printf("hello from OUTSIDE of the if statement!\n");