Homework 1: Data types and Flow control

Due Monday September 29, 2008 at 5:00pm.

Name your files hw1_<number>.cpp, such as hw1_1.cpp for the first program. Email all files as attachments to my Helios account.

  1. (5 points) Building off of the work in Lab 2, write a program that asks the user for two doubles and two integers. Output the results of dividing double 1 by double 2, double 1 by integer 1 and integer 1 by integer 2. The output should resemble the following:
    Enter double 1: 5.0
    Enter double 2: 10.0
    Enter integer 1: 2
    Enter integer 2: 3
    
    5.0 / 10.0 is 0.5.
    5.0 / 2 is 2.5.
    2 / 3 is 0.
    
  2. (5 points) Write a program that asks the user for two integers. Use if/else statements to output the minimum of the two integers. The output should resemble the following:
    Enter integer 1: 3
    Enter integer 2: 2
    
    The minimum of 3 and 2 is 2.
    
  3. (10 points) A common use of text interfaces is to write a menu to the screen and ask the user to select an option. We will start with a very simple menu and refine it throughout the quarter. First, print the following menu to the screen:
      Welcome to the CS221 Homework 1 Menu
      ====================================
      1.  Selection 1
      2.  Selection 2
    
      0.  Exit
      ====================================
      Enter selection:
    
    Read in the user's selection. If the selection is 1, print "You have selected menu item 1." to the screen. If the selection is 2, print "You have selected menu item 2." to the screen. If the selection is greater than 2, print "You have selected an invalid menu item." to the screen. Use a loop to continue printing the menu to the screen, reading the user's selection and printing one of those three messages until the user enters 0.