Homework 6 (UPDATED): More Conditionals
Wednesday, March 07, 2012[Up] [Previous Homework] [Next Homework]
Example solution with extra credit
Complete the following:
- Create a new file called hw06.c
- You are going to create a program that will ask the user some questions about their family
- You will ask for their mother's age when the user was born
- You will ask for their father's age when the user was born
- You will ask for the users current age
- You will then ask for the current year
- 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
- Get the user input to select which menu option to perform
- Based upon the user input, calculate the selected value and print out the result
- 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
- 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
- Note that you may use either switch or if-else logic to determine which code to execute after getting user input
- 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.
- Create a script of you running your program five times, once for each possible calculation.
- Once you are done, use submit to submit two files, hw06.c and typescript
linux3[1]% submit cs104_sheets hw06 hw06.c typescript