Hey guys
I just started working on a problem that states "Write a C++ program for a theater that will keep track of a movie attendee. The program should ask the user to enter their eage and gender. The user should enter a negative number when there are no more ages to enter. The program should then break down the attendees by age and gender. The following age categories should be used:
0-18 years
19-30 years
31 - 40 years
41 - 60 years
Over 60 years
The program should also display how many males and females attended the movie, in addition to computing and displaying the age of all attendees, the age of the youngest attendee, and that of the oldest.
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int age(0), sex(0), youngest(999), oldest(0), M(0), F(0), age1(0), age2(0), age3(0), age4(0), age5(0), totalage(0), totalcount(0);
do
{
cout << "Enter sex \n" <<endl;
cin >> sex;
if (sex != M || sex != F)
{
cout << "Invalid sex entered \n" << endl;
break;
}
cout << "Enter age of attendee \n" << endl;
cin >> age;
if (age < 0)
{
cout << "Invalid age \n" << endl;
break;
}
if (age >=0 && age <= 18)
++age1;
if (age >= 19 && age <= 30)
++age2;
if (age >= 31 && age <= 40)
++age3;
if(age >=41 && age <=60)
++age4;
if (age >=61 && age <=100)
++age5;
if (age < youngest)
youngest += age;
if (age > oldest)
oldest +=age;
++ totalcount;
++ totalage;
} while (age > 0 );
return 0;
}
This is what I have so far and I am very close to breaking it, but I can't seem to reach that point. Help?