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

This is programming for engineers in C. Please supply the proper code for me to

ID: 641890 • Letter: T

Question

This is programming for engineers in C. Please supply the proper code for me to reference off of.

Create a payroll program to store and calculate the payroll for a small company with a maximum of 20 employees.

Program parameters are as follows:

Create a menu with the following options (use a do-while loop):

A or a to add employee info

D or d to display employee info

T or t to display total payroll

S or s to display the info of all employees

Z or z to exit program

The information for each employee is: employee number, hours worked, pay rate per hour, tax deduction.

Use an array of doubles to store employee information.

Option A or a: ask the user for the employee information one value at a time and store it in the array.

Please enter employee number: 2190

Please enter hours worked: 32.50

Please enter pay rate: 9.25

Please enter tax rate deduction: 5.50

Option B or b: ask the user for an employee number as integer and display the information for the corresponding employee (cast the employee number in the array to integer and then compare). If employee number does not match, output a msg. indicating

Explanation / Answer

#include <stdio.h>

struct employee{
   int number;
   double hours;
   double payrate;
   double tax;
};

typedef struct employee employee;

double getPay(employee emp){
   double val = emp.hours * emp.payrate;
   return val - (val * (emp.payrate / 100));
}

double printEmployee(employee emp){
   printf("Info for employee number: %d ", emp.number);
   printf("Hours worked: %.2lf ", emp.hours);
   printf("Pay rate: $%.2lf ", emp.payrate);
   printf("Tax deduction: %.2lf%% ", emp.tax);
   printf("Total Pay: $%.2lf ", getPay(emp));
}

void addEmployee(employee arr[], int count){
   printf("Please enter employee number: ");
   scanf("%d", &(arr[count].number));
   printf("Please enter hours worked: ");
   scanf("%lf", &(arr[count].hours));
   printf("Please enter pay rate: ");
   scanf("%lf", &(arr[count].payrate));
   printf("Please enter tax rate deduction: ");
   scanf("%lf", &(arr[count].tax));
}

void displayId(employee arr[], int count, int id){
   int i = 0;
   for(i = 0; i < count; ++i){
       if(arr[i].number == id){
           printEmployee(arr[i]);
           return;
       }
   }
   printf("No such employee ");
}

void displayAll(employee arr[], int count){
   int i = 0;
   for(i = 0; i < count; ++i){
       printEmployee(arr[i]);
   }
}

double totalPay(employee arr[], int count){
   double pay = 0;
   int i = 0;
   for(i = 0; i < count; ++i){
       pay += getPay(arr[i]);
   }
   return pay;
}

int main(){
   int count = 0, id;
   char ch;
   employee arr[100];
   while(1){
       printf("A or a to add employee info ");
       printf("D or d to display employee info ");
       printf("T or t to display total payroll ");
       printf("S or s to display the info of all employees ");
       printf("Z or z to exit program ");
       printf("Please choose an option: ");
       scanf("%c", &ch);
       switch(ch){
           case 'A':
           case 'a':
               addEmployee(arr, count++);
               break;
           case 'D':
           case 'd':
               printf("Enter an Id: ");
               scanf("%d", &id);
               displayId(arr, count, id);
               break;
           case 'T':
           case 't':
               printf("Total payroll is $%.2lf ", totalPay(arr, count));  
               break;
           case 's':
           case 'S':
               displayAll(arr, count);
               break;
           case 'Z':
           case 'z':
               return 0;
           default:
               printf("Please enter a valid input ");
       }
       scanf("%c", &ch);
   }
   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