The case that falls through is when flying == true
and hieght_of_plane
is greater than 3.
if (is_flying == true)
{
if (hieght_of_plane <= 3)
{
The 2nd if
statement does not have an else
, which is necessary for returning a value.
Edit 1: An else
clause
The else
clause should be used for the "not" case of the if
statement.
For example:
if (is_flying == false)
{
return true;
}
else // This means is_flying == true
{
if (hieght_of_plane <= 3)
{
if (landing_gear == false)
{
is_alive = false ;
return false ;
}
else // implies landing_gear == true
{
return true ;
}
else // implies hieght > 3
{
return ????
}
}
You could also reduce this down to one Boolean expression.
Edit 2: Simplification
There are two functionalities here: Return true
/false
for a combination of conditions and to set is_alive
based on a condition.
Let's say that one condition is true, all others is false.
bool check_for_alive()
{
if (is_flying && (height_of_plane <= 3) && (landing_gear == false))
{
is_alive = false;
}
return is_flying && (height_of_plane <= 3) && (landing_gear == true);
}
Note: The above does not consider the case of `(height_of_plane > 3), since this is not specified in the OP's original code.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…