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.
#include <iostream>
using namespace std;
int main()
{
int age;
int i=1;
int empAges[100];
while (true){
cout<<"\nEnter your age: ";
cin>>age;
empAges[i-1]=age;
if (age>=19 && age<35){
cout<<"\n"<<age <<" is young age";
}
else if (age>=36 && age<=49){
cout<<"\n"<<age <<" is middle age";
}
else if (age>=50 && age<=65){
cout<<"\n"<<age <<" is eldery age ";
}
if (age<0){
break;
}
i++;
}
cout<<i;
int sumAges=0;
for (int j=0;j<i-1;j++)
{
sumAges=sumAges+empAges[j];
}
cout<<"\nSum of ages = "<<sumAges;
cout<<"\nAverage age = "<<sumAges/i;
return 0;
}
Comments
Leave a comment