#include <iostream>
#include <string>
using namespace std;
/* From the book
This program computes taxes
Inputs:
Income and marital status
Outputs:
Tax due
Logic:
Use the marital status to find the correct base and bonus rates and taxes.
combine the base and bonus taxes, and print out the total.
Test Cases:
1) 500, s, 50
2) 1000000, s: $245200
3) 1000000, m: $240400
*/
int main()
{
const double RATE1 = 0.10;
const double RATE2 = 0.25;
const double RATE1_SINGLE_LIMIT = 32000;
const double RATE1_MARRIED_LIMIT = 64000;
double tax1 = 0;
double tax2 = 0;
double income;
cout << "Please enter your income: ";
cin >> income;
cout << "Please enter s for single, m for married: ";
string marital_status;
cin >> marital_status;
if (marital_status == "s")
{
if (income <= RATE1_SINGLE_LIMIT)
{
tax1 = RATE1 * income;
}
else
{
tax1 = RATE1 * RATE1_SINGLE_LIMIT;
tax2 = RATE2 * (income - RATE1_SINGLE_LIMIT);
}
}
else
{
if (income <= RATE1_MARRIED_LIMIT)
{
tax1 = RATE1 * income;
}
else
{
tax1 = RATE1 * RATE1_MARRIED_LIMIT;
tax2 = RATE2 * (income - RATE1_MARRIED_LIMIT);
}
}
double total_tax = tax1 + tax2;
cout << "The tax is $" << total_tax << endl;
return 0;
}
Back to top