Guest User

Untitled

a guest
Dec 9th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.31 KB | None | 0 0
  1.     #include <iostream>
  2.     using namespace std;
  3.         int main ()
  4.     {
  5.             int age, sumSoFar, ageCount1, ageCount2, ageCount3, ageCount4, ageCount5,
  6.                     averageAge, maleCount, femaleCount, youngestAge, oldestAge;
  7.             char gender;
  8.      
  9.             age = 0;
  10.             ageCount1 = 0;
  11.             ageCount2 = 0;
  12.             ageCount3 = 0;
  13.             ageCount4 = 0;
  14.             ageCount5 = 0;
  15.             maleCount = 0;
  16.             femaleCount = 0;
  17.             sumSoFar = 0;
  18.      
  19.             cout << "Enter the age of attendee (negative number to quit): ";
  20.             cin >> age;
  21.  
  22.             youngestAge = age;
  23.             oldestAge = age;
  24.  
  25.             cout << "Enter gender (M or F): ";
  26.             cin >> gender;
  27.  
  28.             if (gender == 'M') {
  29.                     maleCount = maleCount + 1;
  30.             } else if (gender == 'F') {
  31.                     femaleCount = femaleCount + 1;
  32.             }
  33.            
  34.  
  35.            
  36.         while (age != -1){
  37.                     sumSoFar= sumSoFar + age;
  38.                 if (age < youngestAge) {
  39.                     youngestAge = age;
  40.                 } if (age > oldestAge) {
  41.                             oldestAge = age;
  42.                       }
  43.                             if (age <=18 ) {
  44.                             ageCount1++;
  45.                     } else if (age <= 30 ) {
  46.                             ageCount2++;
  47.                     } else if (age <= 40 ) {
  48.                             ageCount3++;
  49.                     } else if (age <= 60 ) {
  50.                             ageCount4++;
  51.                     } else if (age >=61 ) {
  52.                             ageCount5++;
  53.                         }
  54.                     cout << "Enter the age of attendee (negative number to quit): ";
  55.                 cin >> age;
  56.                         if (age != -1) {
  57.                         cout << "Enter gender (M or F): ";
  58.                                 cin >> gender;
  59.                             if (gender == 'M') {
  60.                                     maleCount = maleCount + 1;
  61.                             } else if (gender == 'F') {
  62.                                     femaleCount = femaleCount + 1;
  63.                                     }
  64.                             }
  65.             }
  66.             //maleCount = maleCount +1;
  67.             cout << "age 0 to 18: " << ageCount1 << endl;
  68.             cout << "age 19 to 30: " << ageCount2 << endl;
  69.             cout << "age 31 to 40: " << ageCount3 << endl;
  70.             cout << "over 60: " << ageCount5 << endl;
  71.             cout << "age 41 to 60: " << ageCount4 << endl;
  72.             averageAge = sumSoFar/(ageCount1 + ageCount2 + ageCount3 + ageCount4 + ageCount5);
  73.             cout << "males: " << maleCount << endl
  74.                      << "females: " << femaleCount << endl
  75.                      << "The average age was " << averageAge << endl;
  76.                     if (youngestAge == -1){
  77.                 cout<< "There is no youngest because an "
  78.                     << "age can't be '-1'!";
  79.                 } else {
  80.                                 cout << "The youngest person in attendance was " << youngestAge << "." << endl;}
  81.                             cout << "The oldest person in attendance was " << oldestAge << "." << endl;
  82.        
  83.             system ( "PAUSE" );
  84.             return 0;
  85.     }
Add Comment
Please, Sign In to add comment