COSC175 Selection Homework


Type in Word. Work with a partner and submit one copy per pair.


Partner 1: Name _______________________________


Partner 2: Name _______________________________




For 1 through 11, create an expression using the relational operators, the logical operators, and variable names of your own choosing, no if or variable declaration is necessary.

  1. is a person's age equal to 30?
  2. is a body temperature  greater than 98.6?
  3. is a person's height less than 6 feet?
  4. is the current month 12?
  5. check if the letter input is m
  6. is a person's age equal to 30 and is the person taller than 6 feet?
  7. check if a length is greater than 2 feet and less than 3 feet
  8. taxRate is over 25% and income is less than $20000
  9. temperature is less than or equal to 75 or humidity is less than 70%
  10. age is over 21 and age is less than 60
  11. age is 21 or 22
  12. For what value(s) of x would this condition be true?

        (x < 1) && (x > 10)


  1. For what value(s) of y would this condition be true?

        (y >= 1) && (y <= 10)


Write appropriate if statements for each of the following conditions:

  1. If an angle is equal to 90 degrees, print the message "The angle is a right angle" else print the message "the angle is not a right angle."
  2. If the temperature is above 100 degrees (celsius), display the message "above the boiling point of water," else display the message "below the boiling point of water."
  3. If the number is positive, add the number to a variable called posSum, otherwise add the number to negSum.
  4. If the slope is less than .5, set a variable named flag to zero, else set flag to one.
  5. Write a program to input an integer number. The program should then output the number and a message saying whether the number is positive, negative, or zero.
  6. Write a program to input three numbers and print out the largest number.
  1. Write the statements to input a water temperature (in Fahrenheit) and print out the state of the water freezing, boiling, liquid





Write the code and trace for the following:

1. Design an algorithm that will receive two integers items and display to the screen their sum, difference, product, and quotient. Do not allow divide by zero to occur.

2. Design an algorithm that will read two numbers and an integer code from the screen (print a menu of the choices first). If the code is 1, compute the sum of the two numbers. If the code is 2, compute the difference of the first number minus the second. If the code is 3, compute the product. If the code is 4 and the second number is not 0, compute the quotient (divide the first number by the second). If the code is not 1,2,3, or 4, display an error message. Finally, display the two numbers, the code, and the result (echo the input).