#include<iostream.h>
#include<conio.h>
int main()
{
//declaration
int count1=0, count2=0, count3=0;
float hours, avg, sum=0.0, min=0.0, max=168;
char name[51];
//input
cout<<"Please enter first employee's name :"<<endl;
cin.getline(name,50);
cout<<"Please enter number of hours employee worked per week : ";
cin>>hours;
while(hours != -1)
//-1 is a sentinel value
{
//if...else statement(selection)
if(hours>55)
{ count1++;
if(max<=hours)
max=hours; }
elseif(hours>=35 && hours<=55)
count2++;
elseif(hours<35)
{ count3++;
if(min>=hours)
min=hours; }
sum+=hours;
cout<<endl;
cin.ignore(80,'\n');
cout<<"Please enter next employee's name :"<<endl;
cin.getline(name,50);
cout<<"Please enter number of hours employee worked per week and enter -1 to stop processing : ";
cin>>hours;
}
//process
avg=sum/(count1+count2+count3);
//output
cout<<"The number of employees in each category :"<<endl;
cout<<"HIGHLY PRODUCTIVE : "<<count1<<endl;
cout<<"SATISFACTORY : "<<count2<<endl;
cout<<"OVERPAID : "<<count3<<endl;
cout<<"The highest number of hours employee worked is "<<max<<endl;
cout<<"The lowest number of hours employee worked is "<<min<<endl;
cout<<"The average hours worked : "<<avg;
getch();
return 0;
}
Hint: When you set the max variable in the if block on lines 23-24, you could do more than just that. For example, also storing the name of the employee to another max variable. (You will have to name that variable something other than max of course, since that name is already taken.)