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
|
float calcTaxAmt(int code, float taxableIncome) {
float tax = 0.0;
float taxRate[6] = { .12, .16, .2, .28, .32, .4 };
float taxCaps[4][5] = { { 7550.0, 30650.0, 74200.0, 154800.0, 336550.0 },
{ 15100.0, 61300.0, 123700.0, 188450.0, 336550.0 },
{ 7550.0, 30650.0, 61850.0, 94225.0, 168275.0 },
{ 10750.0, 41050.0, 106000.0, 171650.0, 336550.0 } };
code--; // Compensate for use as index (0-based counting)
{ // Anonymous namespace to hide i
unsigned int i = 0;
for( ; i < 5 && taxableIncome >= taxCaps[code][i]; i++) { // Add up all but the last tax brackets
if(i == 0) {
tax += taxCaps[code][i] * taxRate[i];
} else {
tax += (taxCaps[code][i] - taxCaps[code][i - 1]) * taxRate[i];
} // END if/else
} // END for(i)
if(i == 5) { // CASE : (i < 5) broke the loop
tax += (taxableIncome - taxCaps[code][4]) * taxRate[5];
} else { // CASE : (taxableIncome >= taxCaps[code][i]) broke the loop
tax += (taxableIncome - taxCaps[code][i - 1]) * taxRate[i];
} // if/else
} // END Anonymous namespace
return tax;
} // END calcTaxAmt(code, income)
|