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 have this so far:
#include <iostream>
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:
cout << "Enter weekly salary for this manager: ";
cin >> weeklySalary;
totalPay = weeklySalary;
break;
case 2:
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:
cout << "Enter gross sales for this comission worker:
";
cin >> grossSales;
totalPay = 250 + grossSales * 0.057;
break;
case 4:
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;
}
My question is: I need to be able to get it to count the number of workers paid at the end as all I am getting is 0 even though I am entering pay codes to calculate.
Program Code [C++]
#include <iostream>
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;
// For counting number of each type of
employees
// We need to increment all counts by 1 inside their
appropraite case block
// See below how i have done it
while (paycode != -1)
{
switch (paycode)
{
case 1:
cout <<
"Enter weekly salary for this manager: ";
cin >>
weeklySalary;
totalPay =
weeklySalary;
// Like
that - as it is a manager
managerCount++;
break;
case 2:
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;
hourlyworkerCount++; // Like this
break;
case 3:
cout <<
"Enter gross sales for this comission worker: ";
cin >>
grossSales;
totalPay = 250 +
grossSales * 0.057;
commissionCount++; // Like this
break;
case 4:
cout <<
"Enter number of produced items for this pieceworker: ";
cin >>
items;
cout <<
"Enter pay for each item: ";
cin >>
payPerItems;
totalPay = items
* payPerItems;
pieceworkerCount++; // Like this one
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;
}
// Now lets just check output of the program
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;
}
Sample Output:-
-------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERIES!!!
HIT A THUMBS UP IF YOU DO LIKE IT!!!