// header files #include "Console_IO_Utility.h" // global constants //AZ taxes // AZ tax Baseline RATE const double AZ_TAX_BASELINE_RATE = 0.0259; // AZ tax Baseline LIMIT const double AZ_TAX_BASELINE_LIMIT = 27808.5; // AZ tax First bracket RATE const double AZ_TAX_FIRST_BRACKET_RATE = 0.0334; // AZ tax First bracket LIMIT const double AZ_TAX_FIRST_BRACKET_LIMIT = 55615.5; // AZ tax Second bracket RATE const double AZ_TAX_SECOND_BRACKET_RATE = 0.0417; // AZ tax Second bracket LIMIT const double AZ_TAX_SECOND_BRACKET_LIMIT = 166843.5; // AZ tax MAX bracket RATE const double AZ_TAX_MAX_RATE = 0.045; // Federal taxes // Minimum FED Tax RATE const double FED_TAX_BASELINE_RATE = 0.1000; // FED tax Baseline LIMIT const double FED_TAX_BASELINE_LIMIT = 10275.5; // FED tax First bracket RATE const double FED_TAX_FIRST_BRACKET_RATE = 0.1200; // FED tax First bracket LIMIT const double FED_TAX_FIRST_BRACKET_LIMIT = 41775.5; // FED tax Second bracket RATE const double FED_TAX_SECOND_BRACKET_RATE = 0.2200; // FED tax Second bracket LIMIT const double FED_TAX_SECOND_BRACKET_LIMIT = 89075.5; // FED tax Third bracket RATE const double FED_TAX_THIRD_BRACKET_RATE = 0.2400; // FED tax Third bracket LIMIT const double FED_TAX_THIRD_BRACKET_LIMIT = 170050.5; // FED tax Fourth bracket RATE const double FED_TAX_FOURTH_BRACKET_RATE = 0.3200; // FED tax Fourth bracket LIMIT const double FED_TAX_FOURTH_BRACKET_LIMIT = 215950.5; // FED tax Fifth bracket RATE const double FED_TAX_FIFTH_BRACKET_RATE = 0.3500; // FED tax Fifth bracket LIMIT const double FED_TAX_FIFTH_BRACKET_LIMIT = 539900.5; // AZ tax MAX bracket RATE const double FED_TAX_MAX_RATE = 0.3700; // Other Taxes // SSN Tax RATE const double TAX_SSN = 0.0620; // MC Tax RATE const double TAX_MC = 0.0145; // Percent Conversion, ratio const double PERCENTAGE_CONVERSION = 100; // printing related constants const int TWO_ENDLINES = 2; // constants for table const int TABLE_WIDTH = 46; const int DATA_NAME_WIDTH = 20; const int UNIT_WIDTH = 7; const int VALUE_WIDTH = 15; const char TOP_LINE[] = "=============================================="; const char THICK_LINE_DIVIDER[] = "|============================================|"; const char THIN_LINE_DIVIDER[] = "|--------------------------------------------|"; const char PIPE_SPACE[] = "| "; const char SPACE_PIPE[] = " |"; // function prototypes double calculateFederalTax( double adjustedIncome ); double calculateArizonaTax( double adjustedIncome ); void displayResultsTable( double taxArizona, double taxFederal, double incomeAfterTaxes, double effectiveTax, double taxTotal, double incomeLocked); // main program int main() { // show title // function: printString, printEndline(s) printEndline(); printString( "Dummy tax calculator V0.3" ); printEndline(); printString( TOP_LINE ); printEndlines( TWO_ENDLINES ); // initialize variables/functions double totalIncome, contributionToIRA, adjustedIncome; double taxFederal, taxArizona; double taxSSN, taxMC, taxTotal; double incomeAfterTaxes; double effectiveTax, incomeLocked; // get user input // section title // function: printString, printEndline printString( "Provide your Tax information below." ); printEndline(); // total income $ // function: promptForDouble totalIncome = promptForDouble("Total income $: "); // IRA contributions $ // function: promptForDouble contributionToIRA = promptForDouble("Your IRA contributions $: "); // conduct computations // adjust income by IRA contributions, $ adjustedIncome = totalIncome - contributionToIRA; // calculate federal tax, $ taxFederal = calculateFederalTax(adjustedIncome); // calculate AZ tax, $ taxArizona = calculateArizonaTax(adjustedIncome); // calculate SSN tax, $ taxSSN = adjustedIncome * TAX_SSN; // calculate MC tax, $ taxMC = adjustedIncome * TAX_MC; // calculate Total tax to be payed, $ taxTotal = taxFederal + taxArizona + taxSSN + taxMC; // calculate Income after Tax, $ incomeAfterTaxes = totalIncome - taxTotal; // calculate effective tax rate, % effectiveTax = taxTotal / totalIncome; // calculate % of income locked in IRA, % incomeLocked = (contributionToIRA / totalIncome) * PERCENTAGE_CONVERSION; // display results displayResultsTable( taxArizona, taxFederal, incomeAfterTaxes, effectiveTax, taxTotal, incomeLocked); // end program / return program success return 0; } // supporting functions /* Name: calculateArizonaTax Process: calculates total marginal Arizona tax based on adjusted income Function Input/Parameters: adjustedIncome Function Output/Parameters: none Function Output/Returned: total arizona tax 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; incomeLeft = 0; totalAZTax = 0; // 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; return totalAZTax; } else if(adjustedIncome < AZ_TAX_FIRST_BRACKET_LIMIT) { // check for first bracket and baseline bracket // calculate tax for first and baseline bracket incomeLeft = adjustedIncome - (adjustedIncome * AZ_TAX_BASELINE_RATE); totalAZTax = incomeLeft * AZ_TAX_FIRST_BRACKET_RATE; return totalAZTax; } 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 - (adjustedIncome * AZ_TAX_BASELINE_RATE); incomeLeft = incomeLeft - (incomeLeft * AZ_TAX_FIRST_BRACKET_RATE); totalAZTax = incomeLeft * AZ_TAX_SECOND_BRACKET_RATE; return totalAZTax; } else { // otherwise, apply the max, second, first, and baseline bracket // calculate tax for max, second, first, and baseline bracket incomeLeft = adjustedIncome - (adjustedIncome * AZ_TAX_BASELINE_RATE); incomeLeft = incomeLeft - (incomeLeft * AZ_TAX_FIRST_BRACKET_RATE); incomeLeft = incomeLeft - (incomeLeft * AZ_TAX_SECOND_BRACKET_RATE); totalAZTax = incomeLeft * AZ_TAX_MAX_RATE; } // display results // not needed, returns instead. // return value // returns the final calculated tax return totalAZTax; } /* Name: calculateFederalTax Process: calculates total marginal federal tax based on adjusted income Function Input/Parameters: adjustedIncome Function Output/Parameters: none Function Output/Returned: total federal tax Device Input/Keyboard: none Device Output/Monitor: none Dependencies: none */ double calculateFederalTax(double adjustedIncome) { // define variables // need a variable that holds the amount of money after the last bracket takes from it. // as well as a variable to return the amount of tax paid. double incomeLeft, totalFedTax; incomeLeft = 0; totalFedTax = 0; // get input // input is passed in from the function parameter // do calculations // use if statements to calculate through the progressive tax brackets if (adjustedIncome < FED_TAX_BASELINE_LIMIT) { // check for baseline bracket // calculate tax for baseline bracket totalFedTax = adjustedIncome * FED_TAX_BASELINE_RATE; return totalFedTax; } else if(adjustedIncome < FED_TAX_FIRST_BRACKET_LIMIT) { // check for first bracket and baseline bracket // calculate tax for first and baseline bracket incomeLeft = adjustedIncome - (adjustedIncome * FED_TAX_BASELINE_RATE); totalFedTax = incomeLeft * FED_TAX_FIRST_BRACKET_RATE; return totalFedTax; } else if(adjustedIncome < FED_TAX_SECOND_BRACKET_LIMIT) { // check for second, first, and baseline bracket // calculate tax for second, first, and baseline bracket incomeLeft = adjustedIncome - (adjustedIncome * FED_TAX_BASELINE_RATE); incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FIRST_BRACKET_RATE); totalFedTax = incomeLeft * FED_TAX_SECOND_BRACKET_RATE; return totalFedTax; } else if(adjustedIncome < FED_TAX_THIRD_BRACKET_LIMIT) { // check for third, second, first, and baseline bracket // calculate tax for third, second, first, and baseline bracket incomeLeft = adjustedIncome - (adjustedIncome * FED_TAX_BASELINE_RATE); incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FIRST_BRACKET_RATE); incomeLeft = incomeLeft - (incomeLeft * FED_TAX_SECOND_BRACKET_RATE); totalFedTax = incomeLeft * FED_TAX_THIRD_BRACKET_RATE; return totalFedTax; } else if(adjustedIncome < FED_TAX_FOURTH_BRACKET_LIMIT) { // check for fourth, third, second, first, and baseline bracket // calculate tax for fourth, third, second, first, and baseline bracket incomeLeft = adjustedIncome - (adjustedIncome * FED_TAX_BASELINE_RATE); incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FIRST_BRACKET_RATE); incomeLeft = incomeLeft - (incomeLeft * FED_TAX_SECOND_BRACKET_RATE); incomeLeft = incomeLeft - (incomeLeft * FED_TAX_THIRD_BRACKET_RATE); totalFedTax = incomeLeft * FED_TAX_FOURTH_BRACKET_RATE; return totalFedTax; } else if(adjustedIncome < FED_TAX_FIFTH_BRACKET_LIMIT) { // check for fifth, fourth, third, second, first, and baseline bracket // calculate tax for fifth, fourth, third, second, first, and baseline bracket incomeLeft = adjustedIncome - (adjustedIncome * FED_TAX_BASELINE_RATE); incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FIRST_BRACKET_RATE); incomeLeft = incomeLeft - (incomeLeft * FED_TAX_SECOND_BRACKET_RATE); incomeLeft = incomeLeft - (incomeLeft * FED_TAX_THIRD_BRACKET_RATE); incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FOURTH_BRACKET_RATE); totalFedTax = incomeLeft * FED_TAX_FIFTH_BRACKET_RATE; return totalFedTax; } else { // otherwise, apply the max, fifth, fourth, third, second, first, and baseline bracket // calculate tax for max, fifth, fourth, third, second, first, and baseline bracket incomeLeft = adjustedIncome - (adjustedIncome * FED_TAX_BASELINE_RATE); incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FIRST_BRACKET_RATE); incomeLeft = incomeLeft - (incomeLeft * FED_TAX_SECOND_BRACKET_RATE); incomeLeft = incomeLeft - (incomeLeft * FED_TAX_THIRD_BRACKET_RATE); incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FOURTH_BRACKET_RATE); incomeLeft = incomeLeft - (incomeLeft * FED_TAX_FIFTH_BRACKET_RATE); totalFedTax = incomeLeft * FED_TAX_MAX_RATE; } // display results // not needed, returns instead. // return value // returns the final calculated tax return totalFedTax; } /* Name: displayResultsTable Process: displays (prints) table for tax calculator V0.3 Function Input/Parameters: income after tax, effective tax rate, total tax to be payed, and locked income. Function Output/Parameters: none Function Output/Returned: none Device Input/Keyboard: none Device Output/Monitor: table as showed in example for PA05 Dependencies: printEndline, printString, printCharacter, printStringJustified, printDoubleJustified */ void displayResultsTable(double taxArizona, double taxFederal, double incomeAfterTaxes, double effectiveTax, double taxTotal, double incomeLocked) { // define variables // no variables needed. // get input // input is from the parameters // do calculations // no calculations are done here. // display results // print top line // function: printString, printEndline printEndline(); printString( TOP_LINE ); printEndline(); // print title line // function: printCharacter, printStringJustified, printEndline printCharacter( PIPE ); printStringJustified( "DUMMY TAX CALCULATIONS", TABLE_WIDTH - 2, "CENTER" ); printCharacter( PIPE ); printEndline(); // print thick divider line // function: printString, printEndline printString( THICK_LINE_DIVIDER ); printEndline(); // print sub title line // function: printStringJustified, printString, printCharacter, // printEndline printString( PIPE_SPACE ); printStringJustified( "Data Name", DATA_NAME_WIDTH - 1, "LEFT" ); printCharacter( PIPE ); printStringJustified( "Units", UNIT_WIDTH, "CENTER" ); printString( PIPE_SPACE ); printStringJustified( "Value", VALUE_WIDTH - 2, "CENTER" ); printString( SPACE_PIPE ); printEndline(); // print thick divider line // function: printString, printEndline printString( THICK_LINE_DIVIDER ); printEndline(); // print Arizona tax rate // function: printStringJustified, printString, printCharacter, // printEndline printString( PIPE_SPACE ); printStringJustified( "AZ Tax Rate ", DATA_NAME_WIDTH - 1, "LEFT" ); printCharacter( PIPE ); printStringJustified( "$", UNIT_WIDTH, "CENTER" ); printCharacter( PIPE ); printDoubleJustified( taxArizona, PRECISION, VALUE_WIDTH -1, "RIGHT" ); printString( SPACE_PIPE ); printEndline(); // print thin divider line // function: printString, printEndline printString( THIN_LINE_DIVIDER ); printEndline(); // print Federal tax rate // function: printStringJustified, printString, printCharacter, // printEndline printString( PIPE_SPACE ); printStringJustified( "Fed Tax Rate", DATA_NAME_WIDTH - 1, "LEFT" ); printCharacter( PIPE ); printStringJustified( "$", UNIT_WIDTH, "CENTER" ); printCharacter( PIPE ); printDoubleJustified( taxFederal, PRECISION, VALUE_WIDTH -1, "RIGHT" ); printString( SPACE_PIPE ); printEndline(); // print thin divider line // function: printString, printEndline printString( THIN_LINE_DIVIDER ); printEndline(); // print Effective tax rate // function: printStringJustified, printString, printCharacter, // printEndline printString( PIPE_SPACE ); printStringJustified( "Effective Tax Rate ", DATA_NAME_WIDTH - 1, "LEFT" ); printCharacter( PIPE ); printStringJustified( "%", UNIT_WIDTH, "CENTER" ); printCharacter( PIPE ); printDoubleJustified( effectiveTax * PERCENTAGE_CONVERSION, PRECISION, VALUE_WIDTH - 1, "RIGHT" ); printString( SPACE_PIPE ); printEndline(); // print thin divider line // function: printString, printEndline printString( THIN_LINE_DIVIDER ); printEndline(); // Total tax paid // function: printStringJustified, printString, printCharacter, // printEndline printString( PIPE_SPACE ); printStringJustified( "Tax To Be Paid ", DATA_NAME_WIDTH - 1, "LEFT" ); printCharacter( PIPE ); printStringJustified( "$", UNIT_WIDTH, "CENTER" ); printCharacter( PIPE ); printDoubleJustified( taxTotal, PRECISION, VALUE_WIDTH - 1, "RIGHT" ); printString( SPACE_PIPE ); printEndline(); // print thin divider line // function: printString, printEndline printString( THIN_LINE_DIVIDER ); printEndline(); printString( PIPE_SPACE ); printStringJustified( "Income After Tax ", DATA_NAME_WIDTH - 1, "LEFT" ); printCharacter( PIPE ); printStringJustified( "$", UNIT_WIDTH, "CENTER" ); printCharacter( PIPE ); printDoubleJustified( incomeAfterTaxes, PRECISION, VALUE_WIDTH - 1, "RIGHT" ); printString( SPACE_PIPE ); printEndline(); // print thin divider line // function: printString, printEndline printString( THIN_LINE_DIVIDER ); printEndline(); printString( PIPE_SPACE ); printStringJustified( "Locked in IRA ", DATA_NAME_WIDTH - 1, "LEFT" ); printCharacter( PIPE ); printStringJustified( "%", UNIT_WIDTH, "CENTER" ); printCharacter( PIPE ); printDoubleJustified( incomeLocked, PRECISION, VALUE_WIDTH - 1, "RIGHT" ); printString( SPACE_PIPE ); printEndline(); // print thick divider line // function: printString, printEndline printString( THICK_LINE_DIVIDER ); printEndline(); }