CMPSC 101 - If Statement Worksheet #1 Name -

1. In the right margin, show what output would be displayed by the following program.

#include <iostream>
using namespace std;

int main()
{
    int a = 3;
    int b = 4;
    int c = 8;

    if (a < b)
          cout << "a is less than b" << endl;
    else
          cout << "b is less than a" << endl;
          cout << "b is less than c" << endl;

    return 0;
}// end of main

2. What is the value (TRUE or FALSE) of the following possible if statement control expressions where the integer variables a, b, & c have the following values:
   a = 1, b = 2 & c = 3. Write out the word TRUE or FALSE.

a/ (a < b || c == 2)

b/ (a < b && c == 2)

c/ (3 < b + a)

d/ (b < 1 || a > 0 && b < 0)

e/ (!(b > a))

 

3. Evaluate the following expression where a = 5 and b = 6. Write either TRUE or FALSE.

(a < b || 6 >= b && b < 3)

4. Write an if statement that displays the message "finished" if the value of the variable num is greater than or equal to 5.