CMPSC 101 - Variables Worksheet #7 Name -

Use good style when writing if and switch statements. Use curly braces around all if and else clauses to avoid making dangling else errors.

1. What is the value of the following possible if statement control expressions where a, b, & c are variables with the values: a = 1, b = 2 & c = 3? Write TRUE or FALSE.

a/ (a < b)

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

c/ (b * a + c < 6)

d/ (2 + a * b > 5)

e/ (!(c > b) && a > b)

f/ (b * c % 2 == 0)

g/ (b * c >= 6)

h/ (c + 4 < 0 || a < b && b > a)

3. Write an if/else statement that displays the message "within range " if the value of the integer variable number is greater than or equal to 5 but less than 10. Otherwise, the message "not finished" displays.

 




4. Write a switch structure that displays the message "failed" if the value of the integer variable quizScore is 5. The switch statement should display the message "average" if quizScore is 6, 7, or 8 and it should display "good" if quizScore is 9 or 10. Otherwise, the message "illegal value" should be displayed.






 

 



5. List the following operators in order of overall priority from highest to lowest. For example, with regard to arithmetic operations * is considered to have a higher priority than +.

<   %   *   +   ||   ==   &&