-
Notifications
You must be signed in to change notification settings - Fork 0
/
taxes.c
113 lines (100 loc) · 4.75 KB
/
taxes.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
#include <stdio.h>
// calculates flat tax rate (the total tax percent of this year's income)
double flatTaxRate(double totalTaxes, double yearIncome) {
double flatRate = 100 * (totalTaxes / yearIncome);
return flatRate;
}
// applies the tax rate to values
double applyBracketTaxRate(double taxPercent, double currentAmount) {
return currentAmount * (taxPercent/100);
}
// Eliminates the need for multiple printf statements
void printAmountTaxed(double percentTaxed, double currentBeingTaxed) {
printf("You were taxed %.2lf%% on the next $%.2lf you made which is $%.2lf.\n",
percentTaxed, currentBeingTaxed, applyBracketTaxRate(percentTaxed, currentBeingTaxed));
}
void taxCalculation(double yearIncome) {
double totalTaxes;
double currentRemainingTotal;
double currentBeingTaxed;
currentRemainingTotal = yearIncome;
totalTaxes = 0;
if(currentRemainingTotal > 9875) {
currentBeingTaxed = 9875;
currentRemainingTotal -= 9875;
totalTaxes += applyBracketTaxRate(10, currentBeingTaxed);
printf("You were taxed 10.00%% on the first $%.2lf you made which is $%.2lf.\n",
currentBeingTaxed, applyBracketTaxRate(10, currentBeingTaxed));
if (currentRemainingTotal > 30250) {
currentBeingTaxed = 30250;
currentRemainingTotal -= 30250;
totalTaxes += applyBracketTaxRate(12, currentBeingTaxed);
printAmountTaxed(12, currentBeingTaxed);
if (currentRemainingTotal > 45400) {
currentBeingTaxed = 45400;
currentRemainingTotal -= 45400;
totalTaxes += applyBracketTaxRate(22, currentBeingTaxed);
printAmountTaxed(22, currentBeingTaxed);
if (currentRemainingTotal > 77775) {
currentBeingTaxed = 77775;
currentRemainingTotal -= 77775;
totalTaxes += applyBracketTaxRate(24, currentBeingTaxed);
printAmountTaxed(24, currentBeingTaxed);
if (currentRemainingTotal > 44050) {
currentBeingTaxed = 44050;
currentRemainingTotal -= 44050;
totalTaxes += applyBracketTaxRate(32, currentBeingTaxed);
printAmountTaxed(32, currentBeingTaxed);
if (currentRemainingTotal > 311050) {
currentBeingTaxed = 311050;
currentRemainingTotal -= 311050;
totalTaxes += applyBracketTaxRate(35, currentBeingTaxed);
printAmountTaxed(35, currentBeingTaxed);
if (currentRemainingTotal > 0) {
totalTaxes += applyBracketTaxRate(37, currentRemainingTotal);
printAmountTaxed(37, currentRemainingTotal);
}
} else {
currentBeingTaxed = currentRemainingTotal;
totalTaxes += applyBracketTaxRate(35, currentBeingTaxed);
printAmountTaxed(35, currentBeingTaxed);
}
} else {
currentBeingTaxed = currentRemainingTotal;
totalTaxes += applyBracketTaxRate(32, currentBeingTaxed);
printAmountTaxed(32, currentBeingTaxed);
}
} else {
currentBeingTaxed = currentRemainingTotal;
totalTaxes += applyBracketTaxRate(24, currentBeingTaxed);
printAmountTaxed(24, currentBeingTaxed);
}
} else {
currentBeingTaxed = currentRemainingTotal;
totalTaxes += applyBracketTaxRate(22, currentBeingTaxed);
printAmountTaxed(22, currentBeingTaxed);
}
} else {
currentBeingTaxed = currentRemainingTotal;
totalTaxes += applyBracketTaxRate(12, currentBeingTaxed);
printAmountTaxed(12, currentBeingTaxed);
}
} else {
currentBeingTaxed = currentRemainingTotal;
totalTaxes += applyBracketTaxRate(10, currentBeingTaxed);
currentRemainingTotal -= currentBeingTaxed;
printf("You were taxed 10.00%% on the first $%.2lf you made which is $%.2lf.\n",
currentBeingTaxed, applyBracketTaxRate(10, currentBeingTaxed));
}
// prints final totals
printf("In total you will pay $%.2lf in taxes on the $%.2lf you made this year.\n", totalTaxes, yearIncome);
printf("This would amount to a FLAT tax of %.2lf%% on all of your income.\n", flatTaxRate(totalTaxes, yearIncome));
}
int main() {
double yearsIncome;
printf("Enter your income for the year: ");
scanf("%lf", &yearsIncome);
// calls for calculation of taxes as well as prints all necassary values
taxCalculation(yearsIncome);
return 0;
}