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 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.]  

The program should not be terminated or crashed (terminate abnormally) or enter into an infinite loop while processing invalid data types. It should continue to prompt the user to input the correct data type.

C/C+ language

Solutions

Expert Solution

C CODE:

#include <stdio.h>
#include<stdlib.h>

int main (void)
{
   //variables to store the pieces, code, total pay, weekly pay,sales,hours
   int pieces, emp_code;
   double total_pay = 0;
   double pay, sales, hours;  

   //getting employee code from the user
   printf ("\nEnter employee's number code (-1 to end): ");  
  
   // checking for valid employee code  
   while ( scanf("%d",&emp_code)!= 1)
   {
  
       printf("\nError.Invalid input. Employee code must be 1,2,3,4 ");
       printf("\n\nEnter employee's number code (-1 to end): ");
       fflush(stdin);      
   }

   // while the code is not equal to -1
   while (emp_code != -1)
   {
       // calculating the pay based on the employee code
       switch (emp_code)
       {
           case 1: printf ("\nEnter the manager's pay rate: ");
          
                   //checking for valid input
                   while (scanf("%lf", &pay) != 1)
                   {
                       printf("\nError.Invalid input. Pay rate must be a number. ");
                       printf("\n\nEnter the manager's pay rate: ");
                       fflush(stdin);
                   }

                   // printing the weekly pay
                   printf ("Weekly pay: %.2f\n\n", pay);
                  
                   //adding the pay to the total
                   total_pay += pay;
  
                   break;

           case 2: printf ("\nEnter hourly worker's pay rate: ");
              
                   //checking for valid input
                   while (scanf("%lf", &pay) != 1)
                   {
                       printf("\nError.Invalid input. Pay rate must be a number. ");
                       printf("\n\nEnter hourly worker's pay rate: ");
                       fflush(stdin);
                   }

                   // number of hours worked
                   printf ("\nEnter the number of hours worked: ");
                  
                   // checking for valid input
                   while (scanf("%lf", &hours) != 1)
                   {
                       printf("\nError.Invalid input. Hours must be a number. ");
                       printf("\n\nEnter the number of hours worked: ");
                       fflush(stdin);
                   }
  
                   // calculating the pay
                   if (hours > 40)
                       pay = (pay * 40) + ((hours - 40) * (pay * 1.5));
                   else
                       pay = pay * hours;
        
                   //printing the weekly pay
                   printf ("Weekly pay: %.2f\n\n", pay);
  
                   //adding the pay to the total
                   total_pay += pay;
  
                   break;

           case 3: //getting commission employee sales details
                   printf ("\nEnter commission employee's gross weekly sales: ");
                  
                   // checking for valid input
                   while (scanf("%lf", &sales) != 1)
                   {
                       printf("\nError.Invalid input. Weekly sales must be a number. ");
                       printf("\n\nEnter commission employee's gross weekly sales: ");
                       fflush(stdin);
                   }
  
                   //calculating the weekly pay
                   pay = 250 + (.057 * sales);
                  
                   //displaying the weekly pay
                   printf ("Weekly pay: %.2f\n\n", pay);
  
                   //adding the pay to the total
                   total_pay += pay;
  
                   break;

           case 4: //getting number of pieces
                   printf ("\nEnter the number of pieces completed: ");
                  
                   // checking for valid int input
                   while (scanf("%d", &pieces) != 1)
                   {
                       printf("\nError.Invalid input. Number of pieces must be a number. ");
                       printf("\n\nEnter the number of pieces completed: ");
                       fflush(stdin);
                   }
  
                   //getting pay rate for every piece
                   printf ("\nEnter the employee's per piece pay rate: ");
                  
                   //checking for valid input
                   while (scanf("%lf", &pay) != 1)
                   {
                       printf("\nError.Invalid input. Pay rate must be a number. ");
                       printf("\n\nEnter the employee's per piece pay rate: ");
                       fflush(stdin);
                   }
  
                    // calculating the weekly pay
                   pay = pieces * pay;
  
                    // printing the pay
                   printf ("Weekly pay: %.2f\n\n", pay);
  
                    // adding the pay to the total
                   total_pay += pay;
                  
                   break;

           default: printf ("\nError: You have entered an invalid code.\n");
       }

       // getting the employee code
       printf ("\nEnter employee's number code (-1 to end): ");
       scanf ("%d", &emp_code);
   }

   // printing the total pay
   printf ("\nThe total payroll for the week: %.2f\n", total_pay);

   return 0;
}

SCREENSHOT FOR OUTPUT:


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