+- Modified Spacing, made sure lines don't go above 80 characters, and formatting is better.
215 lines
7.7 KiB
C
215 lines
7.7 KiB
C
// header files
|
|
#include "Console_IO_Utility.h"
|
|
|
|
// global constants
|
|
// Minimum Arizona Tax, %
|
|
const double MIN_AZ_TAX = 2.59;
|
|
// Maximum Arizona Tax, %
|
|
const double MAX_AZ_TAX = 4.50;
|
|
// Minimum Federal Tax, %
|
|
const double MIN_FED_TAX = 10.00;
|
|
// Maximum Federal Tax, %
|
|
const double MAX_FED_TAX = 37.00;
|
|
// SSN Tax, %
|
|
const double TAX_SSN = 6.20;
|
|
// MC Tax, %
|
|
const double TAX_MC = 1.45;
|
|
// Percent Conversion, ratio
|
|
const double PERCENTAGE_CONVERSION = 0.01;
|
|
|
|
// printing related constants
|
|
const int TWO_ENDLINES = 2;
|
|
// constants for table
|
|
const int TABLE_WIDTH = 52;
|
|
const int DATA_NAME_WIDTH = 20;
|
|
const int UNIT_WIDTH = 7;
|
|
const int VALUE_WIDTH = 10;
|
|
const char TOP_LINE[]
|
|
= "====================================================";
|
|
const char THICK_LINE_DIVIDER[]
|
|
= "|==================================================|";
|
|
const char THIN_LINE_DIVIDER[]
|
|
= "|--------------------------------------------------|";
|
|
const char PIPE_SPACE[] = "| ";
|
|
const char SPACE_PIPE[] = " |";
|
|
|
|
// function prototypes
|
|
// none
|
|
|
|
// main program
|
|
int main()
|
|
{
|
|
// show title
|
|
// function: printString, printEndline(s)
|
|
printString("Dummy Tax Calculator");
|
|
printEndline();
|
|
printString(TOP_LINE);
|
|
printEndlines(2);
|
|
|
|
// initialize variables/functions
|
|
double totalIncome, contributionToIRA, adjustedIncome;
|
|
double minTaxFederal, maxTaxFederal, minTaxArizona, maxTaxArizona;
|
|
double taxSSN, taxMC, minTaxTotal, maxTaxTotal;
|
|
double maxIncome, minIncome;
|
|
double minEffectiveTax, maxEffectiveTax;
|
|
|
|
// get user input
|
|
// section title
|
|
printString( "Please provide your information below.\n" );
|
|
totalIncome = promptForInteger("Total Income $: ");
|
|
contributionToIRA = promptForInteger("Your IRA Contributions $: ");
|
|
|
|
// conduct computations
|
|
|
|
// IRA Contributions are subtracted from totalIncome
|
|
// to get a modified income (adjusted).
|
|
adjustedIncome = totalIncome - contributionToIRA;
|
|
|
|
// Calculate the minimum Federal Tax that would have to be paid,
|
|
// using MIN_FED_TAX * PERCENTAGE_CONVERSION * adjustedIncome
|
|
minTaxFederal = MIN_FED_TAX * PERCENTAGE_CONVERSION * adjustedIncome;
|
|
|
|
// Calculate the maximum Federal Tax that would have to be paid,
|
|
// using MAX_FED_TAX * PERCENTAGE_CONVERSION * adjustedIncome
|
|
maxTaxFederal = MAX_FED_TAX * PERCENTAGE_CONVERSION * adjustedIncome;
|
|
|
|
// Calculate the minimum AZ State Tax that would have to be paid,
|
|
// using MIN_AZ_TAX * PERCENTAGE_CONVERSION * adjustedIncome
|
|
minTaxArizona = MIN_AZ_TAX * PERCENTAGE_CONVERSION * adjustedIncome;
|
|
|
|
// Calculate the maximum AZ State Tax that would have to be paid,
|
|
// using MAX_AZ_TAX * PERCENTAGE_CONVERSION * adjustedIncome
|
|
maxTaxArizona = MAX_AZ_TAX * PERCENTAGE_CONVERSION * adjustedIncome;
|
|
|
|
// Calculate the Social Security Tax that would have to be paid,
|
|
// using TAX_SSN * PERCENTAGE_CONVERSION * adjustedIncome
|
|
taxSSN = TAX_SSN * PERCENTAGE_CONVERSION * adjustedIncome;
|
|
|
|
// Calculate the Medicare Tax that would have to be paid,
|
|
// using TAX_MC * PERCENTAGE_CONVERSION * adjustedIncome
|
|
taxMC = TAX_MC * PERCENTAGE_CONVERSION * adjustedIncome;
|
|
|
|
// Calculate the minimum amount of tax that would have to be paid,
|
|
// using minTaxFederal + minTaxArizona + taxSSN + taxMC
|
|
minTaxTotal = minTaxFederal + minTaxArizona + taxSSN + taxMC;
|
|
|
|
// Calculate the maximum amount of tax that would have to be paid,
|
|
// using maxTaxFederal + maxTaxArizona + taxSSN + taxMC
|
|
maxTaxTotal = maxTaxFederal + maxTaxArizona + taxSSN + taxMC;
|
|
|
|
// Calculate the maximum income after tax has been paid,
|
|
// using totalIncome - minTaxTotal
|
|
maxIncome = totalIncome - minTaxTotal;
|
|
|
|
// Calculate the minimum income after tax has been paid,
|
|
// using totalIncome - maxTaxTotal
|
|
minIncome = totalIncome - maxTaxTotal;
|
|
|
|
// Calculate the minimum tax rate,
|
|
// using minTaxTotal / totalIncome / PERCENTAGE_CONVERSION
|
|
minEffectiveTax = (minTaxTotal / totalIncome) / PERCENTAGE_CONVERSION;
|
|
|
|
// Calculate the maximum tax rate,
|
|
// using maxTaxTotal / totalIncome / PERCENTAGE_CONVERSION
|
|
maxEffectiveTax = (maxTaxTotal / totalIncome) / PERCENTAGE_CONVERSION;
|
|
|
|
// 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( "MIN", VALUE_WIDTH - 2, "CENTER" );
|
|
printString( SPACE_PIPE );
|
|
printStringJustified( "MAX", VALUE_WIDTH - 1, "CENTER" );
|
|
printString( SPACE_PIPE );
|
|
printEndline();
|
|
|
|
// print thin divider line
|
|
// function: printString, printEndline
|
|
printString( THICK_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( minEffectiveTax, PRECISION, VALUE_WIDTH -1, "RIGHT" );
|
|
printString( SPACE_PIPE );
|
|
printDoubleJustified( maxEffectiveTax, 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( minTaxTotal, PRECISION, VALUE_WIDTH -1, "RIGHT" );
|
|
printString( SPACE_PIPE );
|
|
printDoubleJustified( maxTaxTotal, 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( minIncome, PRECISION, VALUE_WIDTH -1, "RIGHT" );
|
|
printString( SPACE_PIPE );
|
|
printDoubleJustified( maxIncome, PRECISION, VALUE_WIDTH - 1, "RIGHT" );
|
|
printString( SPACE_PIPE );
|
|
printEndline();
|
|
|
|
// print thick divider line
|
|
// function: printString, printEndline
|
|
printString( THICK_LINE_DIVIDER );
|
|
printEndline();
|
|
|
|
// end program / return program success
|
|
return 0;
|
|
}
|
|
|
|
// supporting functions
|
|
// none
|