Problem to be solved A company has four employee types; 1.) Pay Code 1 is for ma
ID: 643727 • Letter: P
Question
Problem to be solved
A company has four employee types;
1.) Pay Code 1 is for managers who receive a fixed annual salary,
2.) Pay Code 2 is for hourly workers who receive a fixed hourly amount for hours up to 40 hours per week, and 1.5 times that hourly amount for hours above 40 per week,
3.) Pay Code 3 is for commission workers who receive a flat $250.00 plus 5.7% of their gross weekly sales, and
4.) Pay Code 4 is for piece workers who receive an amount per item for each item they produce.
You need to prompt for a user to enter the pay code type of the employee, followed by the appropriate data for that pay code.
You do not know the number of employees in advance or the order in which they will be entered.
After collecting the needed information for the employee, calculate and print the weekly salary for the employee.
Write the program. A switch statement must be used with a case for each pay type.
As a minimum you must have separate functions to accomplish each of the following:
- One function to calculate pay for pay code 1.
- One function to calculate pay for pay code 2.
- One function to calculate pay for pay code 3.
- One function to calculate pay for pay code 4.
These functions will be called from within the respective switch-case AFTER the data for that pay code type is collected from the user.
The functions should NOT print the pay amount. They should only be used to calculate the pay amount.
Again, the function will NOT get the user information OR print the results, but ONLY do the calculation returning the pay amount to the calling function.
Explanation / Answer
#include <stdio.h>
int main (void)
{
/* Declare and initialize variables */
int pieces, code;
float total = 0;
float pay, sales, hours;
/* Prompt user to enter employee code, -1 to end entries */
printf (" Enter 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 ("%f", &pay);
/* Print the weekly pay for the manager */
printf ("Weekly pay is: %.2f ", 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 ("%f", &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: %.2f ", 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 ("%f", &sales);
/* Calculate weekly pay for the employee */
pay = 250 + (.057 * sales);
/* Print the weekly pay */
printf ("Weekly pay is: %.2f ", pay);
/* Add pay to total */
total += pay;
break;
case 4: /* Pieceworker (pay code 4) */
/* Prompt user for the number of pieces completed */
printf (" Enter 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 ("%f", &pay);
/* Calculate weekly pay for the employee */
pay = pieces * pay;
/* Print the weekly pay */
printf ("Weekly pay is: %.2f ", pay);
/* Add pay to total */
total += pay;
break;
default: /* Invalid pay code */
/* Print error message */
printf ("You have entered an invalid code. ");
}
/* Prompt user to enter employee code, -1 to end entries */
printf (" Enter employee's number code (-1 to end): ");
scanf ("%d", &code);
}
/* Print the total pay for the week */
printf (" The total payroll for the week is: %.2f ", total);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.