#include #include using namespace std; int selection; double income, income_sav, total_tax = 0; double mtax_rate, eff_tax_rate; // This assignment is worth 10 points // 5 points for each successful output for single or joint file // -1 if the initial money input is placed into an int variable // -1 for forgetting to setting all outputs to two decimal places // -1 for having only partially correct output in some cases // -1 for not using constants to define brackets and rates // Values are current for USA 2022 tax brackets const int year = 2022; const double // Define the boundaries of each tax bracket s_deduc = 12950, s_bracket1 = 23225, s_bracket2 = 54725, s_bracket3 = 102025, s_bracket4 = 183000, s_bracket5 = 228900, s_bracket6 = 552850; const double // For joint filing j_deduc = 25900, j_bracket1 = 46450, j_bracket2 = 109450, j_bracket3 = 204050, j_bracket4 = 366000, j_bracket5 = 457800, j_bracket6 = 673750; const double // Define the tax rate of each bracket tax_rate0 = 0, tax_rate1 = 0.1, tax_rate2 = 0.12, tax_rate3 = 0.22, tax_rate4 = 0.24, tax_rate5 = 0.32, tax_rate6 = 0.35, tax_rate7 = 0.37; int main() { cout << "Federal Tax Calculator for Calendar Year " << year << endl; cout << "Are you filing single or jointly?\n" << " 1. Single\n" << " 2. Joint\n" << "Select option: "; cin >> selection; cout << "Enter income ($): "; cin >> income; income_sav = income; // back up this value for later switch(selection) // if/else statements can be used here too { case 1: // Single filing if(income > s_bracket6) // determine the marginal tax rate mtax_rate = tax_rate7; else if(income > s_bracket5) mtax_rate = tax_rate6; else if(income > s_bracket4) mtax_rate = tax_rate5; else if(income > s_bracket3) mtax_rate = tax_rate4; else if(income > s_bracket2) mtax_rate = tax_rate3; else if(income > s_bracket1) mtax_rate = tax_rate2; else if(income > s_deduc) mtax_rate = tax_rate1; else mtax_rate = tax_rate0; // Calculate the taxes per bracket, starting from the highest // Logic statements become 1 or 0 only, avoids negative numbers total_tax += (income > s_bracket6)*tax_rate7*(income - s_bracket6); income -= (income > s_bracket6) * (income - s_bracket6); total_tax += (income > s_bracket5)*tax_rate6*(income - s_bracket5); income -= (income > s_bracket5) * (income - s_bracket5); total_tax += (income > s_bracket4)*tax_rate5*(income - s_bracket4); income -= (income > s_bracket4) * (income - s_bracket4); total_tax += (income > s_bracket3)*tax_rate4*(income - s_bracket3); income -= (income > s_bracket3) * (income - s_bracket3); total_tax += (income > s_bracket2)*tax_rate3*(income - s_bracket2); income -= (income > s_bracket2) * (income - s_bracket2); total_tax += (income > s_bracket1)*tax_rate2*(income - s_bracket1); income -= (income > s_bracket1) * (income - s_bracket1); total_tax += (income > s_deduc)*tax_rate1*(income - s_deduc); break; case 2: // Joint filing if(income > j_bracket6) // determine the marginal tax rate mtax_rate = tax_rate7; else if(income > j_bracket5) mtax_rate = tax_rate6; else if(income > j_bracket4) mtax_rate = tax_rate5; else if(income > j_bracket3) mtax_rate = tax_rate4; else if(income > j_bracket2) mtax_rate = tax_rate3; else if(income > j_bracket1) mtax_rate = tax_rate2; else if(income > j_deduc) mtax_rate = tax_rate1; else mtax_rate = tax_rate0; total_tax += (income > j_bracket6)*tax_rate7*(income - j_bracket6); income -= (income > j_bracket6) * (income - j_bracket6); total_tax += (income > j_bracket5)*tax_rate6*(income - j_bracket5); income -= (income > j_bracket5) * (income - j_bracket5); total_tax += (income > j_bracket4)*tax_rate5*(income - j_bracket4); income -= (income > j_bracket4) * (income - j_bracket4); total_tax += (income > j_bracket3)*tax_rate4*(income - j_bracket3); income -= (income > j_bracket3) * (income - j_bracket3); total_tax += (income > j_bracket2)*tax_rate3*(income - j_bracket2); income -= (income > j_bracket2) * (income - j_bracket2); total_tax += (income > j_bracket1)*tax_rate2*(income - j_bracket1); income -= (income > j_bracket1) * (income - j_bracket1); total_tax += (income > j_deduc)*tax_rate1*(income - j_deduc); break; } eff_tax_rate = total_tax/income_sav; cout << fixed << setprecision(2); cout << "Marginal tax rate: " << mtax_rate*100 << '%' << endl; cout << "Federal taxes due: $" << total_tax << endl; cout << "Effective tax rate: " << eff_tax_rate*100 << '%' << endl; return 0; }