-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path015.1_gross_pay_taxes_net_pay_with_hours_worked.c
58 lines (43 loc) · 1.6 KB
/
015.1_gross_pay_taxes_net_pay_with_hours_worked.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
// with functions
#include <stdio.h>
float calcGrossPay(float numberOfHoursWorked) {
float hourlyPayUnderFortyHours = 12.0;
float hourlyPayAboveFortyHours = 18.0;
if (numberOfHoursWorked <= 40.0) {
return (numberOfHoursWorked * hourlyPayUnderFortyHours);
}
else if (numberOfHoursWorked > 40.0) {
return (40.0 * hourlyPayUnderFortyHours) + ((numberOfHoursWorked - 40.0) * hourlyPayAboveFortyHours);
}
}
float calcTaxes(float numberOfHoursWorked) {
float grossPay = calcGrossPay(numberOfHoursWorked);
float taxFirstThreeHun = 0.15;
float taxNextOneFifty = 0.2;
float taxRest = 0.25;
if (grossPay <= 300) {
return grossPay * taxFirstThreeHun;
}
else if (grossPay > 300 && grossPay <= 450) {
return (300 * taxFirstThreeHun) + ((grossPay - 300) * taxNextOneFifty);
}
else if (grossPay > 450) {
// taxes = ((300*taxFirstThreeHun) + (150*taxNextOneFifty) + ((grossPay-450)*taxRest));
return 75 + ((grossPay - 450) * taxRest);
}
}
float calcNetPay(float numberOfHoursWorked) {
return calcGrossPay(numberOfHoursWorked) - calcTaxes(numberOfHoursWorked);
}
int main() {
float numberOfHoursWorked;
printf("Enter the number of hours a person has worked: ");
scanf("%f", &numberOfHoursWorked);
printf("\n");
// numberOfHoursWorked = 30.0; // 40*12 + 5*18 = 570
printf("\n~*~*~*~*~*~*~*~*~*~*~*~*~ \n \n");
printf("Number of Hours Worked: %.2f \n", numberOfHoursWorked);
printf("Gross Pay: %.2f \n", calcGrossPay(numberOfHoursWorked));
printf("Taxes: %.2f \n", calcTaxes(numberOfHoursWorked));
printf("Net Pay: %.2f \n", calcNetPay(numberOfHoursWorked));
}