Phase 2: 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. The average must be printed rounded to the nearest tenth of a year, as shown below. You may not assume any maximum age of attendees!
Don't forget to look at the examples in lesson 4 for help with this!
Sample screen output:
Enter age of attendee (negative number to quit): 34
Enter age of attendee (negative number to quit): 16
Enter age of attendee (negative number to quit): 68
Enter age of attendee (negative number to quit): 53
Enter age of attendee (negative number to quit): 39
Enter age of attendee (negative number to quit): 23
Enter age of attendee (negative number to quit): 21
Enter age of attendee (negative number to quit): -5
age 0 to 18: 1
age 19 to 30: 2
age 31 to 40: 2
age 41 to 60: 1
over 60: 1
The average age was 36.3
The youngest person in attendance was 16
The oldest person in attendance was 68
/*output
Enter age of attendee (negative number to quit): 34
Enter age of attendee (negative number to quit): 16
Enter age of attendee (negative number to quit): 68
Enter age of attendee (negative number to quit): 53
Enter age of attendee (negative number to quit): 39
Enter age of attendee (negative number to quit): 23
Enter age of attendee (negative number to quit): 21
Enter age of attendee (negative number to quit): -1
Age 0 to 18: 1
Age group 19 to 30: 2
Age group 31 to 40: 1
Age group 41 to 60: 1
Over 60: 1
Age group 31 to 40: 1
Age group 41 to 60: 1
Over 60: 1
The average age was 36.2857
The youngest person in attendance was: 0
The oldest person in attendance was: 68
*/
My output should match the top but my age group is off, and my youngest variable refuses to choose sixteen after I stated it cannot be lower than 0.
Any help is appreciated.
/*Michael Brierley, CS 10, 6/21/2018, Dave Harden, Assignment 4.3 (The purpose of this program is to keep track of how many people in each of 5
age categories attended a particular movie and their preference of soda, popcorn, or both.
*/
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int num;
int count;
int sumsoFar;
int youngest = 0, oldest = 0;
int ageGroupOne = 0, ageGroupTwo = 0, ageGroupThree = 0, ageGroupFour =
0, ageGroupFive = 0;
int
main ()
{
double sumsoFar = 0;
count = 0;
cout << "Enter age of attendee (negative number to quit): ";
cin >> num;
while (num >= 0)
{
{
sumsoFar = sumsoFar + num;
cout << "Enter age of attendee (negative number to quit): ";
cin >> num;
count++;
}
{
if (num >= 0 && num <= 18)
++ageGroupOne;
if (num >= 19 && num <= 30)
++ageGroupTwo;
if (num >= 31 && num <= 40)
++ageGroupThree;
if (num >= 41 && num <= 60)
++ageGroupFour;
if (num >= 61 && num <= 100)
++ageGroupFive;
}
//Youngest and Oldest Attendees
if (num < youngest)
youngest = num;
if (num > oldest)
oldest = num;
}
//Age groups of attendees displayed
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";