Question: #include #include 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,
#include
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 (" Enter employee's number code (-1 to end): "); // checking for valid employee code while ( scanf("%d",&emp_code)!= 1) { printf(" Error.Invalid input. Employee code must be 1,2,3,4 "); printf(" Enter 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 (" Enter the manager's pay rate: "); //checking for valid input while (scanf("%lf", &pay) != 1) { printf(" Error.Invalid input. Pay rate must be a number. "); printf(" Enter the manager's pay rate: "); fflush(stdin); }
// printing the weekly pay printf ("Weekly pay: %.2f ", pay); //adding the pay to the total total_pay += pay; break;
case 2: printf (" Enter hourly worker's pay rate: "); //checking for valid input while (scanf("%lf", &pay) != 1) { printf(" Error.Invalid input. Pay rate must be a number. "); printf(" Enter hourly worker's pay rate: "); fflush(stdin); }
// number of hours worked printf (" Enter the number of hours worked: "); // checking for valid input while (scanf("%lf", &hours) != 1) { printf(" Error.Invalid input. Hours must be a number. "); printf(" Enter 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 ", pay); //adding the pay to the total total_pay += pay; break;
case 3: //getting commission employee sales details printf (" Enter commission employee's gross weekly sales: "); // checking for valid input while (scanf("%lf", &sales) != 1) { printf(" Error.Invalid input. Weekly sales must be a number. "); printf(" Enter commission employee's gross weekly sales: "); fflush(stdin); } //calculating the weekly pay pay = 250 + (.057 * sales); //displaying the weekly pay printf ("Weekly pay: %.2f ", pay); //adding the pay to the total total_pay += pay; break;
case 4: //getting number of pieces printf (" Enter the number of pieces completed: "); // checking for valid int input while (scanf("%d", &pieces) != 1) { printf(" Error.Invalid input. Number of pieces must be a number. "); printf(" Enter the number of pieces completed: "); fflush(stdin); } //getting pay rate for every piece printf (" Enter the employee's per piece pay rate: "); //checking for valid input while (scanf("%lf", &pay) != 1) { printf(" Error.Invalid input. Pay rate must be a number. "); printf(" Enter the employee's per piece pay rate: "); fflush(stdin); } // calculating the weekly pay pay = pieces * pay; // printing the pay printf ("Weekly pay: %.2f ", pay); // adding the pay to the total total_pay += pay; break;
default: printf (" Error: You have entered an invalid code. "); }
// getting the employee code printf (" Enter employee's number code (-1 to end): "); scanf ("%d", &emp_code); }
// printing the total pay printf (" The total payroll for the week: %.2f ", total_pay);
return 0; }
Can someone explain this code in detail please
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
