-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule4LabExtraCredit.cpp
More file actions
122 lines (93 loc) · 3.19 KB
/
Copy pathModule4LabExtraCredit.cpp
File metadata and controls
122 lines (93 loc) · 3.19 KB
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
115
116
117
118
119
120
121
122
//************************************************************************
// Author: Rolando Carreon
// Date: mar 28 2025
// Language: C++
// Assignment: Demo
// Description: Hello World Program
//************************************************************************
#include<iostream>
#include<string> // used for getData
#include<iomanip> // used for setting precision
using namespace std;
//function prototypes
// finction asks user to enter the relvant data
void getData(string&, int&, double&, double&);
// function computes and returns tax owed
void taxAmount(string&, int&, double&, double&, double&);
int main()
{
// declare local variables
string maritalStatus;
int children;
double grossSalary;
double pensionRate;
double taxOwed;
getData(maritalStatus, children, grossSalary, pensionRate);
taxAmount(maritalStatus, children, grossSalary, pensionRate, taxOwed);
cout << fixed << setprecision(2); // set by 2 decimal places
cout << "Your Federal Tax Amount is: $" << taxOwed << endl;
return 0;
}
// funciton definitions
void getData(string& maritalStatus, int& children,
double& grossSalary, double& pensionRate)
{
do
{
cout << "What is your marital status[married/single]: ";
cin >> maritalStatus;
if( maritalStatus == "Single" )
{
children = 0;
break;
}
else if( maritalStatus == "Married" )
{
cout << "How many children do you have under 14 years old: ";
cin >> children;
break;
}
else
{
cout << "Invalid choice. Try Again." << endl;
}
} while ( maritalStatus != "Single" && maritalStatus != "Married" );
cout << "What is your gross salary(if married at the two salaries "
<< "together): ";
cin >> grossSalary;
cout << "What percentage of your income is contributed to\n"
<< "a pension fund [0.0 - 6.0 as a percentage]: ";
cin >> pensionRate;
pensionRate = pensionRate / 100; // covert to decimal place
}
void taxAmount(string& maritalStatus, int& children,
double& grossSalary, double& pensionRate, double& taxOwed)
{
double taxRate;
double pensionFund;
double taxableSalary;
// calculate total pension contribution so far
pensionFund = pensionRate * grossSalary;
// subtract pension contribution from the taxable income
taxableSalary = grossSalary - pensionFund;
// looks to see how much exemption is owed based on marital status
if( maritalStatus == "Single" )
taxableSalary -= 4000; // exemption ammoutn for single people
else if( maritalStatus == "Married" )
taxableSalary -= 7000; // exemption amount for married people
if( taxableSalary <= 15000 )
{
taxRate = 0.15;
taxOwed = taxableSalary * taxRate;
}
else if( taxableSalary >= 15001 && taxableSalary <= 40000 )
{
taxRate = 0.25;
taxOwed = 2250 + (taxableSalary - 15000) * taxRate;
}
else
{
taxRate = 0.35;
taxOwed = 8460 + (taxableSalary - 40000) * taxRate;
}
}