Instructional Material: IF Statement Quiz

Content: 

Given the code below, the desired result is for c to end up as 100 if it’s bigger than b, 0 if it is equal to b, and 5.4 if it is less than b.

1) What does b end up being equal to?

2) According to the rules I wrote in words above, what should c be equal to at the end of this code?

3) Does this code do this?

4) Fix the code to have the desired behavior.

float a = 20;
float b = 5;
float c = 10;

if (a > b)
{
    b = 2 * b;
}
else
{
    b = 0;
}

if ( c > b)
{
    c = 100;
}

if (c == b)
{
    c = 0;
}

if (c < b)
{
    c = 5.4;
}

Here are the answers.

Here is a second quiz on if statements.

 

Navigation: