/* * File: tax.cpp * Author: Robert I. Pitts * Last Modified: October 13, 1999 * Topic: Determining Tax from a Table - Lab * ---------------------------------------------------------------- * * This program determines the tax for a given income and filing status. * * The user may enter several income amounts (i.e., from different income * sources). The user must also enter their filing status. The program * sums up the income amounts to determine the total income and looks up * and prints out the tax for that income and filing status. */ #include /***************************** Constants *****************************/ // Maximum # of income amounts this program can handle. This includes the // 0 (zero) income used to mark the end of incomes. #define MAX_INCOMES 10 // Number of rows in the tax table. #define NUM_ROWS 10 // Each row in tax table corresponds to $5000 of income, e.g., $0-$4999, // $5000-$9999, etc. #define EACH_ROW 5000 // Number of filing statuses (columns in tax table). #define NUM_STATUSES 4 // Labels for filing statuses. char *status_label[NUM_STATUSES] = { "Single", "Married Filing Jointly", "Married Filing Separately", "Head of Household" }; /************************ Function Prototypes ************************/ /* * Function: ReadIncome * Usage: ReadIncome(income_list); * * Reads income amounts into the array passed to it until an amount of 0 * (zero) is entered. The zero is stored in the array to mark the end of * incomes. It cannot read in more than MAX_INCOMES amounts (including the * zero), since that is the maximum size of the array passed to it. */ void ReadIncome(int income_list[MAX_INCOMES]); /* * Function: SumIncome * Usage: SumIncome(income_list); * * Sums all the income amounts in the passed array. It knows there are no * more incomes when the value 0 (zero) is reached. */ int SumIncome(int income_list[MAX_INCOMES]); /* * Function: GetTax * Usage: tax = GetTax(tax_table, income, filing_status); * * Takes the tax table and returns the tax owed for the specified income * and filing status. */ int GetTax(int tax_table[NUM_ROWS][NUM_STATUSES], int income, int filing_status); /*************************** Main Program **************************/ int main() { int income_list[MAX_INCOMES]; // Income amounts from different sources int status; // Filing status int income; // Total income int tax_table[NUM_ROWS][NUM_STATUSES] = { { 600, 500, 600, 550 }, { 1200, 1000, 1200, 1100 }, { 1800, 1500, 1800, 1650 }, { 2400, 2000, 2400, 2200 }, { 3000, 2500, 3000, 2750 }, { 3600, 3000, 3600, 3300 }, { 4900, 5950, 5250, 5600 }, { 5600, 6800, 6000, 6400 }, { 6300, 7650, 6750, 7200 }, { 7000, 8500, 7500, 8000 } }; cout << "Welcome to the tax calculator.\n" << "Enter income amounts from each of your income sources rounded\n" << "to the nearest dollar. Enter 0 (zero) when you are done." << endl; ReadIncome(income_list); cout << "\nFiling Statuses:" << endl; for (int i = 0; i < NUM_STATUSES; i++) { cout << "\t" << i << " = " << status_label[i] << endl; } cout << "\nEnter status: "; cin >> status; income = SumIncome(income_list); cout << "\nYou owe $" << GetTax(tax_table, income, status) << " on your income of $" << income << endl; return 0; } /*********************** Function Definitions **********************/ void ReadIncome(int income_list[MAX_INCOMES]) { //FILL IN! } int SumIncome(int income_list[MAX_INCOMES]) { //FILL IN! } int GetTax(int tax_table[NUM_ROWS][NUM_STATUSES], int income, int filing_status) { return tax_table[ /* row index */ ][filing_status]; }