Question: This program is broken down into phases for your convenience only. Please turn in only the final phase. Before turning in your program, please make
This program is broken down into phases for your convenience only. Please turn in only the final phase. Before turning in your program, please make sure that it allows the user to not enter any ages at all, and does something reasonable in this case (i.e., if the user enters a negative number the first time).
Don't use arrays in this program.
Important Hint: You will save yourself a lot of time and anguish if you follow the patterns and examples given in the lesson closely! The main point of this assignment is to ensure that you understand and can reproduce the loop pattern shown in the example in lesson 4.2.
Phase 1: Write a program for a theater that will keep track of how many people in each of 5 age categories attended a particular movie. Use the 5 age categories listed below in the sample screen output. The user will enter a number of ages, entering a negative number when there are no more ages to enter. Your program will then report on how many people in each age group attended. Sample screen output:
Be sure to use named constants for the boundaries of the age groups.
Enter age of attendee (negative number to quit): 34 Enter age of attendee (negative number to quit): 16 Enter age of attendee (negative number to quit): 68 Enter age of attendee (negative number to quit): 53 Enter age of attendee (negative number to quit): 39 Enter age of attendee (negative number to quit): 23 Enter age of attendee (negative number to quit): 21 Enter age of attendee (negative number to quit): -1 age 0 to 18: 1 age 19 to 30: 2 age 31 to 40: 2 age 41 to 60: 1 over 60: 1
Phase 2: Modify your program so that, in addition to the report that the program currently produces, it also gives the average age of the people in attendance, the age of the oldest person in attendance, and the age of the youngest person in attendance. The average must be printed rounded to the nearest tenth of a year, as shown below. You may not assume any maximum age of attendees!
Don't forget to look at the examples in lesson 4 for help with this!
Sample screen output:
Enter age of attendee (negative number to quit): 34 Enter age of attendee (negative number to quit): 16 Enter age of attendee (negative number to quit): 68 Enter age of attendee (negative number to quit): 53 Enter age of attendee (negative number to quit): 39 Enter age of attendee (negative number to quit): 23 Enter age of attendee (negative number to quit): 21 Enter age of attendee (negative number to quit): -5 age 0 to 18: 1 age 19 to 30: 2 age 31 to 40: 2 age 41 to 60: 1 over 60: 1 The average age was 36.3 The youngest person in attendance was 16 The oldest person in attendance was 68
Phase 3: Modify your program so that it also asks for each attendee's food preference ('p' for popcorn, 's' for soda, 'b' for both). Your program should then report this data as well.
Hint: The lessons contain an example of a loop like this where two questions are asked. Follow the pattern in that example.
Sample screen output:
Enter age of attendee (negative number to quit): 34 Enter food preference ('p' for popcorn, 's' for soda, 'b' for both): s Enter age of attendee (negative number to quit): 16 Enter food preference ('p' for popcorn, 's' for soda, 'b' for both): b Enter age of attendee (negative number to quit): 68 Enter food preference ('p' for popcorn, 's' for soda, 'b' for both): b Enter age of attendee (negative number to quit): 53 Enter food preference ('p' for popcorn, 's' for soda, 'b' for both): s Enter age of attendee (negative number to quit): 39 Enter food preference ('p' for popcorn, 's' for soda, 'b' for both): p Enter age of attendee (negative number to quit): 23 Enter food preference ('p' for popcorn, 's' for soda, 'b' for both): s Enter age of attendee (negative number to quit): 21 Enter food preference ('p' for popcorn, 's' for soda, 'b' for both): s Enter age of attendee (negative number to quit): -1 age 0 to 18: 1 age 19 to 30: 2 age 31 to 40: 2 age 41 to 60: 1 over 60: 1 food preference popcorn: 1 food preference soda: 4 food preference both: 2 The average age was 36.3 The youngest person in attendance was 16 The oldest person in attendance was 68 Your program should allow the user to not enter any ages at all (i.e. the user enters a negative number the first time). In that case it should print a message to explain what happened and then end execution.
Turn in your source code from phase 3 and your output. Turn in only one output, and make it match the sample screen output given above for phase 3 exactly.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
