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 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 and Age group
1.Young employees From 19 till 35
Middle Age group 36 till 49 (inclusive)
2.Elderly 50 till 65
Please note the below points:
1. Demonstrate the use of loops to solve this problem.
2. A sentinel should be utilised.
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int age,c;
int sum = 0;
int average = 0;
// Take the wmployee age
cout<<"Enter the number of employees"<<endl;
cin>>c;
cout<<"Enter age: ";
cin>>age;
while (age>0)
{
//add all the employee age
sum +=age;
//get the employee average
average = sum/c;
//Take the age input if is positive
cout<<"Enter age: ";
cin>>age;
}
//Display the company total age sum
cout << "\nThe company age sum is "<<sum<<endl;
//Display the company average age
cout << "\nThe company average age is "<<average<<endl;
if(average>=19 && average<=35)
{
cout<<"Young employees from 19 till 35: "<<average<<endl;
}
if(average>=36 && average<=49)
{
cout<<"Middle Age group: "<<average<<endl;
}
if(average>=50 && average<=65)
{
cout<<"Elderly 50 till 65"<<average<<endl;
}
return 0;
}
Comments
Leave a comment