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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
#include <iostream>
#include <iomanip>
#include <string>
#define personalExempt 3900
#define standardDeduct 6100
#define toPercent 100
using namespace std;
const double TAX_RATES[] = {0.1,0.15,0.25,0.28,0.33,0.35,0.396};
const double TAX_BRACKET[] = {0, 8925, 36250, 73200, 111525, 199175, 225000};
enum{TIER1, TIER2, TIER3, TIER4, TIER5, TIER6, TIER7};
struct Income
{
string name;
double AGI;
double taxableIncome;
double taxes[7];
double totalTaxes;
double disposable;
};
void ReadInfo (Income* info);
void CalcTaxes(double agi, Income* taxPtr);
int TaxPartition(double taxedIncome, Income* taxPart);
void TaxBreakdown(Income* taxPtr, int count);
double TaxDue(Income* taxPtr, int count);
void TaxReport(Income* report, int count);
void PrintLine(int size, char ch);
int main()
{
Income user;
ReadInfo(&user);
CalcTaxes(user.AGI, &user);
return 0;
}
void ReadInfo (Income* info)
{
bool valid;
cout << "Name: ";
getline(cin, info->name);
do
{
cout << "Adjusted Gross Income: ";
cin >> info->AGI;
if (cin.fail() || info->AGI <= 0)
{
cin.clear();
valid = false;
cout << "Error: That was not a valid input\n";
}
else
{
valid = true;
}
cin.ignore(1000,'\n');
}while (!valid);
}
void CalcTaxes(double agi, Income* taxPtr)
{
double taxedIncome;
int count;
taxPtr->taxableIncome = agi - personalExempt - standardDeduct;
taxedIncome = taxPtr->taxableIncome;
count = TaxPartition(taxedIncome, taxPtr);
TaxBreakdown(taxPtr, count);
TaxDue(taxPtr, count);
taxPtr->disposable = taxPtr->taxableIncome - taxPtr->totalTaxes;
}
int TaxPartition(double taxedIncome, Income* taxPart)
{
int i = 0;
bool more = true;
int count = 0;
do
{
if (taxPart->taxableIncome > TAX_BRACKET[i+1])
{
count++;
}
else if (taxPart->taxableIncome > TAX_BRACKET[6])
{
count = 6;
more = false;
}
else
{
more = false;
}
i++;
}while(more);
return count;
}
void TaxBreakdown(Income* taxPtr, int count)
{
switch (count)
{
case TIER1:
if (taxPtr->taxableIncome <= 0)
{
cout << "Tax Exemptions exceed taxable income!\n";
}
else
taxPtr->taxes[count] = (taxPtr->taxableIncome - TAX_BRACKET[count]) * TAX_RATES[count];
break;
case TIER2:
case TIER3:
case TIER4:
case TIER5:
case TIER6:
case TIER7:
for (int i = 0; i < count; i++)
{
taxPtr->taxes[i] = (TAX_BRACKET[i+1] - TAX_BRACKET[i]) * TAX_RATES[i];
}
taxPtr->taxes[count] = (taxPtr->taxableIncome - TAX_BRACKET[count]) *TAX_RATES[count];
break;
}
}
double TaxDue(Income* taxPtr, int count)
{
taxPtr->totalTaxes = 0;
for(int i = 0; i <= count; i++)
{
taxPtr->totalTaxes += taxPtr->taxes[i];
}
return taxPtr->totalTaxes;
}
void TaxReport(Income* report, int count)
{
}
void PrintLine(int size, char ch)
{
cout << setw(size) << setfill(ch)
<< "" << setfill(' ') << endl;
}
|