next up previous
Next: goto Statement Up: If Statement Previous: Logical Operators

Activity

1.
What is the difference in results from the left and right program parts:
    if (1 == 2)                     if (1 == 2) {            
       cout << "Strange ";             cout << "Strange ";  
       cout << "Mathematics";          cout << "Mathematics";}




2.
Circle the program part which is correct:
    if (1 == 2)                     if (1 == 2)     
       cout << "Strange ";             cout << "Strange ";
                                       cout << "Mathematics";
    else                            else
       cout << "Plain ";               cout << "Plain ";
       cout << "Mathematics";          cout << "Mathematics";

3.
For if ... if ... else ..., does the else belong to the first or second if?

4.
How could you safely reformulate the previous construct so that confusion is not possible?

5.
Circle the program part which is correct:
    if (a<b || a==b)                 if (a<b && a==b)       
       cout << "a not > b";             cout << "a not > b";
    else cout << "a > b";            else cout << "a > b";

6.
The condition a>b is equivalent to:
    b<a                               b<a || b==a

7.
The condition a<=b is equivalent to:
    b>a || b==a                       ! (b<=a)

8.
The condition a<b is equivalent to:
    b>a || b==a                       ! (b<=a)

9.
The expression a<1 || a>3 && a!=0 is equivalent to:
    a<1 || (a>3 && a!=0)              (a<1 || a>3) && a!=0

10.
So, is the previous expression true when a is zero?



Yousef Haik
2/23/1998