// header file #include "Arizona_Tax_Utility.h" // Defined Functions: /* Name: calculateArizonaTax Process: calculates total marginal Arizona tax based on adjusted income Function Input/Parameters: adjustedIncome Function Output/Parameters: none Function Output/Returned: totalAZTax Device Input/Keyboard: none Device Output/Monitor: none Dependencies: none */ double calculateArizonaTax(double adjustedIncome) { // define variables // need a variable that holds the amount of money after the last bracket takes from it. double incomeLeft, totalAZTax; double maxBaselineTax, maxFirstTax, maxSecondTax; incomeLeft = 0; totalAZTax = 0; maxBaselineTax = AZ_TAX_BASELINE_LIMIT * AZ_TAX_BASELINE_RATE; maxFirstTax = maxBaselineTax + (AZ_TAX_FIRST_BRACKET_LIMIT - AZ_TAX_BASELINE_LIMIT) * AZ_TAX_FIRST_BRACKET_RATE; maxSecondTax = maxFirstTax + (AZ_TAX_SECOND_BRACKET_LIMIT - AZ_TAX_FIRST_BRACKET_LIMIT) * AZ_TAX_SECOND_BRACKET_RATE; // get input // input is passed in from the function parameter // do calculations // use if statements to calculate through the progressive tax brackets if (adjustedIncome < AZ_TAX_BASELINE_LIMIT) { // check for baseline bracket // calculate tax for baseline totalAZTax = adjustedIncome * AZ_TAX_BASELINE_RATE; } else if(adjustedIncome < AZ_TAX_FIRST_BRACKET_LIMIT) { // check for first bracket and baseline bracket // calculate tax for first and baseline bracket incomeLeft = adjustedIncome - AZ_TAX_BASELINE_LIMIT; totalAZTax = maxBaselineTax + (incomeLeft * AZ_TAX_FIRST_BRACKET_RATE); } else if(adjustedIncome < AZ_TAX_SECOND_BRACKET_LIMIT) { // check for second, first, and baseline bracket // calculate tax for second, first, and baseline bracket incomeLeft = adjustedIncome - AZ_TAX_FIRST_BRACKET_LIMIT; totalAZTax = maxFirstTax + (incomeLeft * AZ_TAX_SECOND_BRACKET_RATE); } else { // otherwise, apply the max, second, first, and baseline bracket // calculate tax for max, second, first, and baseline bracket incomeLeft = adjustedIncome - AZ_TAX_SECOND_BRACKET_LIMIT; totalAZTax = maxSecondTax + (incomeLeft * AZ_TAX_MAX_RATE); } // display results // not needed, returns instead. // return value // returns the final calculated tax return totalAZTax; }