Your company wants to collect the total number of age groups within the company and calculate the
average age of employees and the classification (see below table) within the company.
You are required to write a program in C++ that will ask the user to enter the integer age. Determine
in which group allocation each employee belong (refer to table below) and calculate the total Age sum and the company average age. The program should populate a report showing all the
information. The user should enter a negative value to indicate that they are done.
Description Age group
Young employees From 19 till 35
Middle Age group 36 till 49 (inclusive)
Elderly 50 till 65
#include <iostream>
using namespace std;
int main()
{
int Young = 0;
int Middle = 0;
int Elderly = 0;
int Sum = 0;
int age;
while (true)
{
cout << "Enter employee age (0 - to exit): ";
cin >> age;
if (age == 0) break;
if (age >= 19 && age <= 35) Young++;
if (age >= 36 && age <= 49) Middle++;
if (age >= 50 && age <= 65) Elderly++;
if (age >= 66 || age <= 18) continue;
Sum += age;
}
cout << "Young employees From 19 till 35: " << Young << endl;
cout << "Middle employees From 36 till 49: " << Middle << endl;
cout << "Elderly employees From 50 till 65: " << Elderly << endl;
cout << "Sum of all ages of employees is: " << Sum << endl;
if (Elderly + Middle + Young != 0)
{
cout << "Average age is: " << (double)Sum / (Elderly + Middle + Young) << endl;
}
system("pause");
return 0;
}
Comments
Leave a comment