Hi there. I am having trouble finishing this. I think my code also might be a little out of order, due to doing this in various steps. Here's the 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 sure that it does something reasonable if the user enters a negative number the first time.
Phase I: 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:
Phase II: 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. Sample screen output:
Phase III: Modify your program so that it also asks for the gender of each attendee. Your program should then break the attendance down by gender as well as by age. Sample screen output:
THIS IS WHAT THE OUTPUT SHOULD BE IN THE END:
Enter age of attendee (-1 to quit): 34
Enter gender (M or F): M
Enter age of attendee (-1 to quit): 16
Enter gender (M or F): M
Enter age of attendee (-1 to quit): 68
Enter gender (M or F): F
Enter age of attendee (-1 to quit): 53
Enter gender (M or F): F
Enter age of attendee (-1 to quit): 39
Enter gender (M or F): F
Enter age of attendee (-1 to quit): 23
Enter gender (M or F): F
Enter age of attendee (-1 to quit): 21
Enter gender (M or F): F
Enter age of attendee (-1 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
males: 2
females: 5
The average age was 36.
The youngest person in attendance was 16.
The oldest person in attendance was 68.
**I still need to get the program to quit when -1 is entered, and find the number of males, females, and calculate the average age.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
//Variables
int age = 0;
int ageGroupOne, ageGroupTwo, ageGroupThree, ageGroupFour, ageGroupFive;
int youngest;
int oldest;
int counter = 0;
char gender;
char M;
char F;
int main()
{
for (int i=0; i <=80; i++)
{
//Get the age of attendees
cout << "Enter age of attendee (-1 to quit): ";
cin >> age;
//Get the gender of attendees
cout <<" Enter gender (M or F): ";
cin >> gender;
if (age < 0)
{
cout << "Invalid age \n" << endl;
}
//Group attendee inputs by age
else if (age >=0 && age <= 18)
++ageGroupOne;
else if (age >= 19 && age <= 30)
++ageGroupTwo;
else if (age >= 31 && age <= 40)
++ageGroupThree;
else if(age >=41 && age <=60)
++ageGroupFour;
else if (age >=61 && age <=100)
++ageGroupFive;
//Get attendee gender inputs from user
if (gender == M)
cin >> M;
cout << M;
if (gender == F)
cin >> F;
}
//Find the youngest and oldest attendee entered
while (age != -1)
{
if (counter == 0)
{
oldest = age;
youngest = age;
}
else
{
if (age > oldest && age != -1)
oldest = age;
else if (age < youngest && age != -1)
youngest = age;
}
counter ++;
}
//Display age groupings
cout << "Age 0 to 18: ";
cout << ageGroupOne;
cout << "\n";
cout << "Age group 19 to 30: ";
cout << ageGroupTwo;
cout << "\n";
cout << "Age group 31 to 40: ";
cout << ageGroupThree;
cout << "\n";
cout << "Age group 41 to 60: ";
cout << ageGroupFour;
cout << "\n";
cout << "Over 60: ";
cout << ageGroupFive;
}
|
Thanks for your help