Question

In: Computer Science

A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who...

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.

Solutions

Expert Solution

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!!!


Related Solutions

A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who...
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 for each of the items they produce—each pieceworker in this company works on only one type of item). Write...
A company pays its employees as managers (who receive a fixed weekly salary)
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...
A company pays its employees as managers (who receive a fixed weekly salary)
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 for each of the items they produce—each pieceworker in this company works on only one type of item). Write...
A company pays its employees as managers (who receive a fixedweekly salary), hourly workers (who...
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...
Problem Description 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
Programming Language: C++Problem Description 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...
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 “—1.5 times their hourly wage — for overtime hours worked )
USING C++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 “—1.5 times their hourly wage — for overtime hours worked ), commission workers (who receive $250 plus 5.7 percent of their gross weekly sales), or pieceworkers (who receive a fixed amount of money per item for each of the items they produce). Write a program...
Many universities pay their teaching assistants (TA) or associate instructors (AI) as weekly workers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 10 hours they work and “time-and-a-half”
Needs to be written in CMany universities pay their teaching assistants (TA) or associate instructors (AI) as weekly workers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 10 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 7.1 times their gross weekly work hours), or pieceworkers (who receive a fixed amount of money for each of...
A company is trying to decide to pay employees a fixed salary or an hourly wage....
A company is trying to decide to pay employees a fixed salary or an hourly wage. If the company decides to pay salaries, which statement is true? (2pts) Paying salaries would have no affect on fixed costs or the contribution margin. Salaries decrease the total fixed costs and the contribution margin would be lower. Salaries increase total fixed costs and the contribution margin would be higher. 2) A company is trying to decide to pay employees a fixed salary or...
Grouper Company pays its office employee payroll weekly. Below is a partial list of employees and...
Grouper Company pays its office employee payroll weekly. Below is a partial list of employees and their payroll data for August. Because August is their vacation period, vacation pay is also listed. Employee --Earnings to July 31----    Weekly Pay-----    Vacation Pay to Be Received in August Mark Hamill $5,010    $200    --- Karen Robbins $4,310 $150    $300 Brent Kirk    $3,510 $110 $220 Alec Guinness    $8,210 $250 --- Ken Sprouse    $8,810 $330    $660...
Pina Company pays its office employee payroll weekly. Below is a partial list of employees and...
Pina Company pays its office employee payroll weekly. Below is a partial list of employees and their payroll data for August. Because August is their vacation period, vacation pay is also listed. Employee Earnings to July 31 Weekly Pay Vacation Pay to Be Received in August Mark Hamill $5,200 $240 - Karen Robbins 4,500 190 $380 Brent Kirk 3,700 150 300 Alec Guinness 8,400 290 - Ken Sprouse 9,000 370 740 Assume that the federal income tax withheld is 10%...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT