Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main ()
- {
- int age, sumSoFar, ageCount1, ageCount2, ageCount3, ageCount4, ageCount5,
- averageAge, maleCount, femaleCount, youngestAge, oldestAge;
- char gender;
- age = 0;
- ageCount1 = 0;
- ageCount2 = 0;
- ageCount3 = 0;
- ageCount4 = 0;
- ageCount5 = 0;
- maleCount = 0;
- femaleCount = 0;
- sumSoFar = 0;
- cout << "Enter the age of attendee (negative number to quit): ";
- cin >> age;
- youngestAge = age;
- oldestAge = age;
- cout << "Enter gender (M or F): ";
- cin >> gender;
- if (gender == 'M') {
- maleCount = maleCount + 1;
- } else if (gender == 'F') {
- femaleCount = femaleCount + 1;
- }
- while (age != -1){
- sumSoFar= sumSoFar + age;
- if (age < youngestAge) {
- youngestAge = age;
- } if (age > oldestAge) {
- oldestAge = age;
- }
- if (age <=18 ) {
- ageCount1++;
- } else if (age <= 30 ) {
- ageCount2++;
- } else if (age <= 40 ) {
- ageCount3++;
- } else if (age <= 60 ) {
- ageCount4++;
- } else if (age >=61 ) {
- ageCount5++;
- }
- cout << "Enter the age of attendee (negative number to quit): ";
- cin >> age;
- if (age != -1) {
- cout << "Enter gender (M or F): ";
- cin >> gender;
- if (gender == 'M') {
- maleCount = maleCount + 1;
- } else if (gender == 'F') {
- femaleCount = femaleCount + 1;
- }
- }
- }
- //maleCount = maleCount +1;
- cout << "age 0 to 18: " << ageCount1 << endl;
- cout << "age 19 to 30: " << ageCount2 << endl;
- cout << "age 31 to 40: " << ageCount3 << endl;
- cout << "over 60: " << ageCount5 << endl;
- cout << "age 41 to 60: " << ageCount4 << endl;
- averageAge = sumSoFar/(ageCount1 + ageCount2 + ageCount3 + ageCount4 + ageCount5);
- cout << "males: " << maleCount << endl
- << "females: " << femaleCount << endl
- << "The average age was " << averageAge << endl;
- if (youngestAge == -1){
- cout<< "There is no youngest because an "
- << "age can't be '-1'!";
- } else {
- cout << "The youngest person in attendance was " << youngestAge << "." << endl;}
- cout << "The oldest person in attendance was " << oldestAge << "." << endl;
- system ( "PAUSE" );
- return 0;
- }
Add Comment
Please, Sign In to add comment