You Just got your 1st internship as C++ developer CONGRATULATIONS, your manager gives you your 1 st task to solve below. PROBLEM SPECIFICATION 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 belongs (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
Please note the below points:
1. Demonstrate the use of loops to solve this problem. See example output
2. A sentinel should be utilized.
#include <iostream>
using namespace std;
int main()
{
int YoungAge = 0;
int MiddleAge = 0;
int ElderlyAge = 0;
int TotalAge = 0;
int age;
while (true)
{
cout << "Employee age is (negative - to exit): ";
cin >> age;
if (age < 0) break;
if (age >= 19 && age <= 35) YoungAge++;
if (age >= 36 && age <= 49) MiddleAge++;
if (age >= 50 && age <= 65) ElderlyAge++;
if (age >= 66 || age <= 18)
{
cout << "Wrong age was entered!" << endl;
continue;
}
TotalAge += age;
}
cout << "Young employees From 19 till 35: " << YoungAge << endl;
cout << "Middle employees From 36 till 49: " << MiddleAge << endl;
cout << "Elderly employees From 50 till 65: " << ElderlyAge << endl;
cout << "Sum of all ages of employees is: " << TotalAge << endl;
if (TotalAge != 0)
{
cout << "Average age is: " << (double)TotalAge / (ElderlyAge + MiddleAge + YoungAge) << endl;
}
system("pause");
return 0;
}
Comments
Thanks for the answer
Leave a comment