Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem Description A company pays its employees as managers (who receive a fixe

ID: 3801992 • Letter: P

Question

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 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 paycode. 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 paycode. SampleOutput Enter paycode (-1 to end): 3 Commission worker selected. Enter gross weekly sales: 4000 Commission worker’s pay is $ 478.00 Enter paycode (-1 to end): 2 Hourly worker is selected.Enter hourly salary: 4.5 Enter the total hours worked: 20 Worker’s pay is $90.00 Enter paycode (-1 to end):-1 Summary of Payouts Employee Categories Number Paid Managers 0 Hourly Workers 1 Commission Workers 0 Piece Workers 0

Explanation / Answer

Ans: The below code is explained with comments.

#include <stdio.h>

/* main */

int main (void)

{

/* Declre & initialize the variables */

/* int pieces and code

int pieces, code;

/* total sgould be float */

float total = 0;

/* pay_sales_hours

float pay, sales, hours;

/* this Prompts the user to enter employee_code i.e -1 to the end entries */

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

scanf ("%d", &code);

/* -1 has not been entered */

while (code != -1)

{

/* Calculte the employee"s pay based on the pay_code */

switch (code)

{

/* case-1 */

case 1: /* pay_code 1 for managr*/

printf ("Enter the manager's pay rate: ");

scanf ("%f", &pay);

/* it Prints weekly pay for manager */

printf ("Weekly pay is: %.2f ", pay);

/* Adds manager's_pay to the total_pay */

total += pay;

/* break */

break;

/* case-2 */

case 2: /* pay_code-2 for hourly Worker*/

/* user input */

printf ("Enter hourly worker's pay rate: ");

scanf ("%f", &pay);

/* number of hours_workd */

printf ("Enter the number of hours worked: ");

/* scanf */

scanf ("%f", &hours);

/* calculation as required rate */

/* if hours greater than 40 */

if (hours > 40)

pay = (pay * 40) + ((hours - 40) * (pay * 1.5));

/* else */

else

/* pay is pay*hours

pay = pay * hours;

/* to Print the weekly_pay for employee */

printf ("Weekly pay is: %.2f ", pay);

/* add weekly_pay to the total_pay */

total += pay;

/* break */

break;

/* case-3 */

case 3: /* pay_code-3 Commission employee*/

/* this Prompts the user for employee's gross weekly_sales */

printf ("Enter the commission employee's_gross weekly_sales: ");

/* scanf */

scanf ("%f", &sales);

/*to-Calculate weekly_pay for an employee */

/* pay is 250 + (.057*sales)

pay = 250 + (.057 * sales);

/* to Print weekly_pay */

printf ("Weekly pay is: %.2f ", pay);

/* should Add pay to the total */

total += pay;

/* break */

break;

/* case-4 */

case 4: /* pay_code-4 for Pieceworker */

/* user input (completed) */

printf (" Enter the number of pieces completed: ");

/*scanf pieces */

scanf ("%d", &pieces);

/* per piece pay_rate */

printf ("Enter the employee's per piece pay_rayte: ");

/* scanf */

scanf ("%f", &pay);

/*to Calculate weekly_pay for employee which equals to-(pieces*pay) */

pay = pieces * pay;

/* Prints the weekly_pay */

printf ("Weekly pay is: %.2f ", pay);

/* Add pay to the total (total+pay)*/

total += pay;

/* break */

break;

/* default_case */

default: /* Invalid pay_code */

/* Print the err message */

printf ("You have enterd an invalid_code. ");

}

/* Prompt the user to enter employee_code i.e, -1 to the end_entries */

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

scanf ("%d", &code);

}

/* this Prints the total_pay for week */

printf (" The total payroll for the week is: %.2f ", total);

/* return 0 */

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote