In: Computer Science
A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and “time-and-a-half,” i.e. 1.5 times their hourly wage, for overtime hours worked), commission workers (who receive $250 plus 5.7% of their gross weekly sales), or pieceworkers (who receive a fixed amount of money per item for each of the items they produce-each pieceworker in this company works on only one type of item). Write a program to compute the weekly pay for each employee. You do not know the number of employees in advance. Each type of employee has its own pay code: Managers have pay code 1, hourly workers have code 2, commission workers have code 3 and pieceworkers have code 4. Use a switch to compute each employee’s pay based on that employee’s pay code. Within the switch, prompt the user to enter the appropriate facts your program needs to calculate each employee’s pay based on that employee’s pay code.
I was wondering how I could get the sample output to be like this as seen below:
The sample output should be like this:
Summary of Payouts
Employee Categories Number Paid
-------------------------------------------------------------------------
Managers 0 0
Hourly Workers 1 $ 478.00
Commission Workers 1 $ 90.00
Piece Workers 0 0
I have this so far:
#include
using namespace std;
int main()
{
int paycode =0;
double weeklySalary;
double hourlySalary;
int hours;
double grossSales;
double payPerItems;
int items;
double totalPay;
int managerCount=0;
int hourlyworkerCount=0;
int commissionCount=0;
int pieceworkerCount=0;
cout << "Enter paycode for next employee (-1 for exit):
";
cin >> paycode;
while (paycode != -1)
{
switch (paycode)
{
case 1:
managerCount++;
cout << "Enter weekly salary for this manager: ";
cin >> weeklySalary;
totalPay = weeklySalary;
break;
case 2:
hourlyworkerCount++;
cout << "Enter hourly salary for this hourly worker: ";
cin >> hourlySalary;
cout << "Enter number of hours worked: ";
cin >> hours;
if (hours <= 40)
totalPay = hours * hourlySalary;
else
totalPay = 40 * hourlySalary + (hours - 40) * hourlySalary *
1.5;
break;
case 3:
commissionCount++;
cout << "Enter gross sales for this comission worker:
";
cin >> grossSales;
totalPay = 250 + grossSales * 0.057;
break;
case 4:
pieceworkerCount++;
cout << "Enter number of produced items for this pieceworker:
";
cin >> items;
cout << "Enter pay for each item: ";
cin >> payPerItems;
totalPay = items * payPerItems;
break;
default:
cout << "Wrong input! Please try again." << endl;
totalPay = 0;
break;
}
cout << "Total weekly pay is: " << totalPay <<
endl << endl;
cout << "Enter paycode for next employee (-1 for exit):
";
cin >> paycode;
}
cout << "Summary of payouts" << endl;
cout << "Employee Categories Number Paid" <<
endl;
cout << "# of Managers paid: " << managerCount <<
endl;
cout << "# of Hourly Workers : "<< hourlyworkerCount
<< endl;
cout << "# of Commissions Employees : "<<
commissionCount << endl;
cout << "# of PieceWorkers : "<< pieceworkerCount
<< endl;
return 0;
}
Code:
#include
#include
using namespace std;
int main()
{
int paycode =0;
int managerCount=0;
double weeklySalary;
double totalPay_mngr = 0;
int hourlyworkerCount=0;
double totalPay_hr_Workers = 0;
double hourlySalary;
int hours;
int commissionCount=0;
double totalPay_commision_Workers = 0;
double grossSales;
int pieceworkerCount=0;
double totalPay_piece_worker = 0;
double payPerItems;
int items;
cout << "Enter paycode for next employee (-1 for exit):
";
cin >> paycode;
while (paycode != -1)
{
switch (paycode)
{
case 1:
managerCount++;
cout << "Enter weekly salary for this manager: ";
cin >> weeklySalary;
totalPay_mngr += weeklySalary;
break;
case 2:
hourlyworkerCount++;
cout << "Enter hourly salary for this hourly worker: ";
cin >> hourlySalary;
cout << "Enter number of hours worked: ";
cin >> hours;
if (hours <= 40)
totalPay_hr_Workers += hours * hourlySalary;
else
totalPay_hr_Workers += 40 * hourlySalary + (hours - 40) *
hourlySalary * 1.5;
break;
case 3:
commissionCount++;
cout << "Enter gross sales for this comission worker:
";
cin >> grossSales;
totalPay_commision_Workers += 250 + grossSales * 0.057;
break;
case 4:
pieceworkerCount++;
cout << "Enter number of produced items for this pieceworker:
";
cin >> items;
cout << "Enter pay for each item: ";
cin >> payPerItems;
totalPay_piece_worker += items * payPerItems;
break;
default:
cout << "Wrong input! Please try again." << endl;
}
cout << "Enter paycode for next employee (-1 for exit):
";
cin >> paycode;
}
cout << "\n" << endl;
cout << "Summary of payouts" << endl;
cout << setw(24) << left << "Employee
Categories\tNumber\tpaid" << endl;
cout << setw(24) << left << "Managers:" <<
managerCount << "\t$" << totalPay_mngr
<
cout << setw(24) << left << "Commissions
Workers:"<< commissionCount << "\t$" <<
totalPay_commision_Workers << endl;
cout << setw(24) << left <<
"PieceWorkers:"<< pieceworkerCount << "\t$" <<
totalPay_piece_worker << endl;
return 0;
}
-------------------------------------
Output: