A movie theater manage in town wants to know how many audiences are children or adults group and their average age in each group. In this homework, you will assist the manager by showing the total number and average age of children group and adults group.
Follow the instruction.
1. Include <iostream> and use namespace std statement.
2. Begin main( ) function. Depending on the software you are using, you may use either void main( ) or int main( ). When you use int main( ), don't forget return 0; statement at the end of main( ) function.
3. Create double variables for children total number, adults total number, children average age, and adults average age - you can use any variable names (suggestion: ChildrenTotal, AdultsTotal, ChildrenAgeTotal, AdultsAgeTotal). Initialize all those variables with 0.
4. Create a 40-element, double array (named Age) with the initial value of the followings:
{13, 45, 32, 28, 25, 13, 10, 7, 22, 17,
9, 32, 29, 34, 14, 7, 41, 38, 15, 49,
16, 14, 26, 10, 32, 9, 37, 11, 43, 48,
25, 13, 31, 26, 35, 43, 14, 9, 25, 32}
5. Create an integer variable i, which will be used as a counter variable in a for-statement.
6. Write a for-statement that begins with i = 0 ; less than equal to 39 ; increments by 1 at each loop. This counter variable i is used as an index of the Age array. The loop contains one if-statement: if Age[i] is less than 18, add the value of Age[i] to ChildrenAgeTotal and add 1 to ChidrenTotal; otherwise (means if Age is greater than or equal to 18), add the value of Age[i] to AdultsAgeTotal and add 1 to AdultsTotal.
* Using cout statements, display the follow information.
7. In the first line, display "Total Number of Children: " and ChildrenTotal.
In the second line, display "Total Age of Children: " and ChildrenAgeTotal.
In In the third line, display "Average Age of Children: " and ChildrenAgeTotal / ChildrenTotal.
In the fourth line, display "Total Number of Adults: " and AdultsTotal.
In the fifth line, display "Total Age of Adults: " and AdultsAgeTotal.
In the sixth line, display "Average Age of Adults: " and AdultsAgeTotal / AdultsTotal.
8. Close the main( ) function. If you use int main( ), do not forget to add system("pause"); return 0; statement at the end.