Question

In: Computer Science

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 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 paycode 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 paycode. Within the switch, prompt the user (i.e., the payroll clerk) to enter the appropriate facts your program needs to calculate each employee’s pay based on that employee’s paycode. [Note: You can input values of type double using the conversion specifier %lf with scanf.]  

Solutions

Expert Solution

Program

#include

int main (void)
{
   /* Declare and initialize variables */
   int pieces, code;
   double total = 0;
   float hours;
   double pay, sales;

   /* Prompt user to enter employee code, -1 to end entries */
   printf ("\nEnter employee's number code (-1 to end): ");
   scanf ("%d", &code);

   /* While -1 has not been entered */
   while (code != -1)
   {
       /* Calculate employee's pay based on pay code */
       switch (code)
       {
           case 1: /* Manager (pay code 1) */
               /* Prompt user for manager's pay rate */
               printf ("Enter the manager's pay rate: $");
               scanf ("%lf", &pay);

               /* Print the weekly pay for the manager */
               printf ("Weekly pay is: $ %.2lf\n\n", pay);
              
               /* Add manager's pay to total pay */
               total += pay;

               break;

           case 2: /* Hourly Worker (pay code 2)*/
               /* Prompt user for hourly worker's pay rate */
               printf ("Enter hourly worker's pay rate: $");
               scanf ("%lf", &pay);

               /* Prompt user for number of hours worked */
               printf ("Enter the number of hours worked: ");
               scanf ("%f", &hours);

               /* If hours worked is greater than 40,
               calculate pay rate for first 40 hours,
               then calculate pay rate ("time-and-a-half")
               for hours worked over 40, and add these
               values together. Otherwise, calculate
               regular pay rate */
               if (hours > 40)
                   pay = (pay * 40) + ((hours - 40) * (pay * 1.5));
               else
                   pay = pay * hours;
  
               /* Print the weekly pay for the employee */
               printf ("Weekly pay is: $ %.2lf\n\n", pay);

               /* Add weekly pay to total pay */
               total += pay;

               break;

           case 3: /* Commission employee (pay code 3) */
               /* Prompt user for employee's gross weekly sales */
               printf ("Enter commission employee's gross weekly sales: ");
               scanf ("%lf", &sales);

               /* Calculate weekly pay for the employee */
               pay = 250 + (.057 * sales);
              
               /* Print the weekly pay */
               printf ("Weekly pay is: $ %.2lf\n\n", pay);

               /* Add pay to total */
               total += pay;

               break;

           case 4: /* Pieceworker (pay code 4) */
               /* Prompt user for the number of pieces completed */
               printf ("\nEnter the number of pieces completed: ");
               scanf ("%d", &pieces);

               /* Prompt user for per piece pay rate */
               printf ("Enter the employee's per piece pay rate: $");
               scanf ("%lf", &pay);

   /* Calculate weekly pay for the employee */
               pay = pieces * pay;

   /* Print the weekly pay */
               printf ("Weekly pay is: $ %.2lf\n\n", pay);

   /* Add pay to total */
               total += pay;
              
               break;

           default: /* Invalid pay code */
               /* Print error message */
               printf ("You have entered an invalid code.\n");
       }

       /* Prompt user to enter employee code, -1 to end entries */
       printf ("\nEnter employee's number code (-1 to end): ");
       scanf ("%d", &code);
   }

   /* Print the total pay for the week */
   printf ("\nThe total payroll for the week is: $ %.2lf\n", total);

   return 0;
}

Output

Enter employee's number code (-1 to end): 1
Enter the manager's pay rate: $3000
Weekly pay is: $ 3000.00


Enter employee's number code (-1 to end): 2
Enter hourly worker's pay rate: $25
Enter the number of hours worked: 45
Weekly pay is: $ 1187.50


Enter employee's number code (-1 to end): 3
Enter commission employee's gross weekly sales: 100
Weekly pay is: $ 255.70


Enter employee's number code (-1 to end): 4

Enter the number of pieces completed: 150
Enter the employee's per piece pay rate: $5
Weekly pay is: $ 750.00


Enter employee's number code (-1 to end): 5
You have entered an invalid code.

Enter employee's number code (-1 to end): -1

The total payroll for the week is: $ 5193.20


Related Solutions

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), 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), 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 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...
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...
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%...
Marigold Company pays its office employee payroll weekly. Below is a partial list of employees and...
Marigold 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