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 123 124 125 126 127 128 129 130
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
// User-defined Simple Data Types
enum status {Single, Married};
// Function Prototypes
void getData(int& numberOfChildren, double& grossIncome, double& pensionAmount, status& state);
void taxAmount(int numberOfChildren, double grossIncome, double pensionAmount, status state);
// Constant Variables
const int SINGLE_EXEMPTION = 4000;
const int MARRIED_EXEMPTION = 7000;
const int PERSONAL_EXEMPTION = 1500;
const double MAX_PENSION_PERCENT = 0.06;
const int MID_BASE_RATE = 2250;
const int HIGH_BASE_RATE = 8460;
const double MID_TAX_PERCENT = 0.25;
const double HIGH_TAX_PERCENT = 0.35;
int main()
{
int numberOfChildren;
double grossIncome, pensionAmount;
status state;
getData(numberOfChildren, grossIncome, pensionAmount, state);
taxAmount(numberOfChildren, grossIncome, pensionAmount, state);
return 0;
}
void getData(int& numberOfChildren, double& grossIncome, double& pensionAmount, status& state)
{
double pensionPercent;
string maritalStatus;
cout << fixed << showpoint << setprecision(2);
cout << "Federal Tax Program" << endl;
do
{
cout << "Please enter your marital status ('Single' or 'Married'): ";
cin >> maritalStatus;
cout << endl;
if (maritalStatus == "Married")
state = Married;
else if (maritalStatus == "Single")
state = Single;
else
cout << "Invalid Entery." << endl;
}
while (! (state == Married || state == Single));
switch (state)
{
case Married:
cout << "Please enter you and your spouce's gross income: ";
cin >> grossIncome;
cout << endl;
cout << "Please enter the number of children you have under the age of 14: ";
cin >> numberOfChildren;
cout << endl;
do
{
cout << "Please enter the percentage of your gross income that was put towards a pension plan (0-6): ";
cin >> pensionPercent;
cout << endl;
}
while (! (pensionPercent > 0 && pensionPercent <= 6));
pensionPercent = pensionPercent / 100;
pensionAmount = grossIncome * pensionPercent;
break;
case Single:
cout << "Please enter your gross income: ";
cin >> grossIncome;
cout << endl;
do
{
cout << "Please enter the percentage of your gross income that was put towards a pension plan (0-6): ";
cin >> pensionPercent;
cout << endl;
} while (! (pensionPercent > 0 && pensionPercent <= 6));
pensionPercent = pensionPercent / 100;
pensionAmount = grossIncome * pensionPercent;
break;
}
}
void taxAmount(int numberOfChildren,double grossIncome,double pensionAmount,status state)
{
double taxableIncome, totalTaxes;
int totalExemption;
switch (state)
{
case Married:
totalExemption = numberOfChildren + 2;
taxableIncome = grossIncome - pensionAmount - MARRIED_EXEMPTION - (totalExemption * PERSONAL_EXEMPTION);
cout << "Your taxable income is $" << taxableIncome << endl;
break;
case Single:
totalExemption = 1;
taxableIncome = grossIncome - pensionAmount - SINGLE_EXEMPTION - (totalExemption * PERSONAL_EXEMPTION);
cout << "Your taxable income is $" << taxableIncome << endl;
break;
}
if (taxableIncome < 15000)
totalTaxes = taxableIncome * 0.15;
else if (taxableIncome > 15000 && taxableIncome <= 40000)
totalTaxes = ((taxableIncome - 15000) * MID_TAX_PERCENT) + MID_BASE_RATE;
else
totalTaxes = ((taxableIncome - 40000) * HIGH_TAX_PERCENT) + HIGH_BASE_RATE;
if (totalTaxes > 0)
cout << "The total amount of taxes you owe is $" << totalTaxes << endl;
else
cout << "You don't owe any taxes this year." << endl;
}
|