-
Notifications
You must be signed in to change notification settings - Fork 0
/
FederalTax.cpp
49 lines (43 loc) · 1.72 KB
/
FederalTax.cpp
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
#include <iostream>
using namespace std;
// Function to get user input
void getData(char &maritalStatus, int &numChildren, double &grossSalary, double &pensionPercentage) {
cout << "Enter your marital status (s for single, m for married): ";
cin >> maritalStatus;
if (maritalStatus == 'm') {
cout << "Enter the number of children under the age of 14: ";
cin >> numChildren;
}
cout << "Enter your gross salary: $";
cin >> grossSalary;
cout << "Enter the percentage of gross income contributed to a pension fund: ";
cin >> pensionPercentage;
}
// Function to calculate tax amount
double taxAmount(char maritalStatus, int numChildren, double grossSalary, double pensionPercentage) {
double taxableIncome, standardExemption, pensionContribution, taxAmount;
if (maritalStatus == 's') {
standardExemption = 4000;
} else if (maritalStatus == 'm') {
standardExemption = 7000 + (numChildren * 1000);
}
pensionContribution = (pensionPercentage / 100) * grossSalary;
taxableIncome = grossSalary - standardExemption - pensionContribution;
if (taxableIncome <= 15000) {
taxAmount = taxableIncome * 0.15;
} else if (taxableIncome > 15000 && taxableIncome <= 40000) {
taxAmount = 2250 + ((taxableIncome - 15000) * 0.25);
} else {
taxAmount = 8460 + ((taxableIncome - 40000) * 0.35);
}
return taxAmount;
}
int main() {
char maritalStatus;
int numChildren = 0;
double grossSalary, pensionPercentage, tax;
getData(maritalStatus, numChildren, grossSalary, pensionPercentage);
tax = taxAmount(maritalStatus, numChildren, grossSalary, pensionPercentage);
cout << "The federal tax owed is: $" << tax << endl;
return 0;
}