Homework 6 (UPDATED): More Conditionals

Wednesday, March 07, 2012     


[Up] [Previous Homework] [Next Homework]


Example solution

Example solution with extra credit

Complete the following:

  1. Create a new file called hw06.c
  2. You are going to create a program that will ask the user some questions about their family
  3. You will ask for their mother's age when the user was born
  4. You will ask for their father's age when the user was born
  5. You will ask for the users current age
  6. You will then ask for the current year
  7. You will then present a menu as shown below:

    Type 1 to calculate your mother's current age
    Type 2 to calculate you father's current age
    Type 3 to calculate the year you were born
    Type 4 to calculate the year your mother was born
    Type 5 to calculate the year your father was born
    

  8. Get the user input to select which menu option to perform
  9. Based upon the user input, calculate the selected value and print out the result
  10. Note that whether you want to get and store the menu input as a character (eg. char '1') or as a number (eg. int 1) is up to you
  11. If you decide to use character input, make sure you take care of the extra return as discussed in class multiple times now, and as referenced in the note from previous homework
  12. Note that you may use either switch or if-else logic to determine which code to execute after getting user input
  13. EXTRA CREDIT: Modify the program so that you present the menu first, and then ONLY ask for the relevant data items necessary to calculate the selected menu option. ie, for menu option 1 (mother's current age) you would only need to ask for the user's current age and the mother's age when user was born.
  14. Create a script of you running your program five times, once for each possible calculation.
  15. Once you are done, use submit to submit two files, hw06.c and typescript

    linux3[1]% submit cs104_sheets hw06 hw06.c typescript