CS136-Projects/PA06-1019/Arizona_Tax_Utility.c
cdez 5119f73add Modified Project 5 File, Added Project 6 Files
+- Project 5 File
++ Project 6 Files (Utils and Main)
2022-10-19 20:22:36 -07:00

70 lines
2.5 KiB
C

// 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;
}