/*
Brian Elias
2/15/07
Dave Harden
CIS10
Assignment 4.4
file: a4 point 4.cpp
This program prompts the user to input the age and gender of
any guests attending a movie. Then the program will display
the amount of guests between certain age brackets, the amount
of guests of certain genders, as well as the average and
highest/lowert ages. Of course, though, the user can stop
entering ages by inputting a negative number.
*/
//****************** this line is 70 characters long **********
#include
using namespace std;
int main()
{
int attendeeAge; //The age of the guest
int averageAge; //The average age of all guests combined
int sumOfAges; //The sum of all of the guests' ages
int count0to18; //The number of guests from ages 0-18
int count19to30; //The number of guests from ages 19-30
int count31to40; //The number of guests from ages 31-40
int count41to60; //The number of guests from ages 41-60
int count60over; //The number of guests over 60
int youngest; //The age of the youngest guest
int oldest; //The age of the oldest guest
char attendeeGender; //The gender of the guests
int countMale; //The number of male guests
int countFemale; //The number of female guests
count0to18 = 0;
count19to30 = 0;
count31to40 = 0;
count41to60 = 0;
count60over = 0;
countMale = 0;
countFemale = 0;
oldest = attendeeAge;
sumOfAges = 0;
cout << "Enter age of attendee (negative number to quit): ";
cin >> attendeeAge;
while (attendeeAge >= 0)
{
if (attendeeAge >= 0 && attendeeAge < 19)
count0to18++;
else if (attendeeAge >= 19 && attendeeAge < 31)
count19to30++;
else if (attendeeAge >= 31 && attendeeAge < 41)
count31to40++;
else if (attendeeAge >= 41 && attendeeAge < 61)
count41to60++;
else if (attendeeAge > 60)
count60over++;
sumOfAges = sumOfAges + attendeeAge;
if (attendeeAge <>= 0)
youngest = attendeeAge;
else if (attendeeAge > oldest)
oldest = attendeeAge;
cout << "Enter gender (M or F): ";
cin >> attendeeGender;
{
if (attendeeGender == 'M')
countMale++;
else if (attendeeGender == 'F')
countFemale++;
}
cout << "Enter age of attendee "
<< "(negative number to quit): ";
cin >> attendeeAge;
}
cout << endl;
cout << "age 0 to 18: " << count0to18 << endl;
cout << "age 19 to 30: " << count19to30 << endl;
cout << "age 31 to 40: " << count31to40 << endl;
cout << "age 41 to 60: " << count41to60 << endl;
cout << "over 60: " << count60over << endl << endl;
{
if ((count0to18 + count19to30 + count31to40 + count41to60
+ count60over) > 0)
{
averageAge = sumOfAges/(count0to18 + count19to30
+ count31to40 + count41to60 + count60over);
cout << "males: " << countMale << endl;
cout << "females: " << countFemale << endl;
cout << "The average age was " << averageAge
<< "." << endl;
cout << "The youngest person in attendance was "
<< youngest << "." << endl;
cout << "The oldest person in attendance was "
<< oldest << "." << endl;
}
else cout << "Nobody attended the show.";
}
return 0;
}
Friday, February 16, 2007
(untitled)
by Kitkinder @ 03:53 [edit] [link]
RANDOM CODE STUFF:
This post has no comments / Add a Comment