-
Notifications
You must be signed in to change notification settings - Fork 93
/
Employee_Payroll.c
114 lines (91 loc) · 3.24 KB
/
Employee_Payroll.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <stdio.h>
#include<stdlib.h>
struct Employee_Payroll
{
float empId;
float hourlyWorked;
float hourlyRate;
float grossPay;
float regularPay;
float overtimePay;
float fed_tax_deduction;
float ssno_tax_deduction;
float finally_net_pay;
};
void Payroll_record(int n, struct Employee_Payroll *ptr)
{
int i;
for ( i = 0; i < n; ++i)
{
printf("Enter Employees ID: ");
scanf("%f", &((ptr+i)->empId));
printf("Enter Employees hourly Worked: ");
scanf("%f", &((ptr+i)->hourlyWorked));
printf("Enter Employees hourly Rate: ");
scanf("%f", &((ptr+i)->hourlyRate));
if ((ptr+i)->hourlyWorked > 40){
(ptr+i)->overtimePay = 1.5*((ptr+i)->hourlyWorked - 40) * (ptr+i)->hourlyRate;
}
else{
(ptr+i)->overtimePay = 0.00;
}
(ptr+i)->regularPay = (ptr+i)->hourlyWorked * (ptr+i)->hourlyRate;
(ptr+i)->grossPay = 7*((ptr+i)->regularPay + (ptr+i)->overtimePay);
(ptr+i)->fed_tax_deduction = 0.275 * (ptr+i)->grossPay;
(ptr+i)->ssno_tax_deduction = 0.0772 * (ptr+i)->grossPay;
(ptr+i)->finally_net_pay = (ptr+i)->grossPay - ((ptr+i)->fed_tax_deduction + (ptr+i)->ssno_tax_deduction );
}
}
void payroll_record_display(int n, struct Employee_Payroll* ptr)
{
int i;
printf("\nEmp No Hourly Rate Hours Worked Reg. Pay OT Pay Gross Pay Fed Tax Other Tax Net Pay");
for ( i = 0; i < n; ++i)
{
printf("\n%.0f $%.2f %.2f $%.2f $%.2f $%.2f $%.2f $%.2f %.2f",(ptr+i)->empId, (ptr+i)->hourlyRate, (ptr+i)->hourlyWorked, (ptr+i)->regularPay, (ptr+i)->overtimePay, (ptr+i)->grossPay,
(ptr+i)->fed_tax_deduction, (ptr+i)->ssno_tax_deduction, (ptr+i)->finally_net_pay);
}
}
int main()
{
struct Employee_Payroll *ptr, record;
int n;
int choice, num;
printf("Enter the no of Employees: ");
scanf("%d", &n);
do
{
printf("\n\n");
printf("1. Enter a new payroll record\n");
printf("2. Display all payroll summary information\n");
printf("3. Quit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
while(choice < 1 || choice > 4)
{
printf("\nPlease enter a valid choice");
printf("\nEnter 1, 2 or 3: ");
scanf("%d", &choice);
}
switch (choice) {
case 1:
{
//allocting the memory of n no of struct employee
ptr = (struct Employee_payroll*)malloc(n* sizeof(struct Employee_Payroll));
ptr = &record;
Payroll_record(n, &ptr);
break;
}
case 2:
{
payroll_record_display(n, &ptr);
break;
}
case 3:
{
printf("\nGoodbye! ");
}
}
} while (choice <= 2 && choice >= 1);
return 0;
}