Oct 2, 2011 at 12:53am UTC
#include <iostream>
#include <cstdlib>
#include <math.h>
#include <iomanip>
using namespace std;
const string FILLER = " ";
int main()
{
int w1 = 20;
int w2 = 20;
int w3 = 20;
int w4 = 16;
//variable declarations
string firstname,lastname;
int marital_status;
float gross_income;
const float tax_rate_0 = 0.10;
const float tax_rate_1 = 0.15;
const float tax_rate_2 = 0.25;
string single, married;
//Prompt the user to enter their name.
cout << "Please enter your full name: ";
cin >> firstname >> lastname;
cout <<endl;
//2. Enter marital status.
cout << "Please enter your Marital Status: 1 for Single or 2 for Married ";
cin >> marital_status;
cout <<endl;
//3. Enter gross income.
cout << "Please enter the amount of gross income: ";
cin >> gross_income;
cout <<endl;
cout <<endl;
cout << setprecision(2) << fixed; // set numeric output
cout << setw(w1) << left << "Taxpayer" << FILLER
<< setw(w2) << left << "Marital" << FILLER
<< setw(w3) << left << "Income" << FILLER
<< setw(w4) << left << "Tax Due" << FILLER;
cout << setw(w1) << left << "" << FILLER
<< setw(w2) << left << "Status" << FILLER
<< setw(w3) << left << "Earned" << FILLER
<< setw(w4) << left << "" << FILLER;
cout<< setw(w1) << left << "________________________________________________________________________" << FILLER<<endl;
cout << setw(w1) << left << lastname
<< setw(w2-18) << right << marital_status
<< setw(w3+1) << right << "$" << gross_income;
// Calculate tax-single part.
if (marital_status==1 && gross_income <= 8000 )
cout<< setw(w4-1)<<"$"<<((gross_income-0)*tax_rate_0);
else {
if (marital_status==1 && gross_income <= 32000){
cout<< setw(w4-1)<<"$"<<((gross_income-8000)*tax_rate_1+ 800); }
else {
if (marital_status==1 && gross_income > 32000){
cout << setw(w4-1)<<"$" <<((gross_income-32000)*tax_rate_2 + 4400);}
}
}
//Calculate tax for married part.
if (marital_status== 2 && gross_income <= 16000){
cout << setw(w4-1)<<"$" <<((gross_income-0)*tax_rate_0);}
else {
if (marital_status==2 && gross_income <= 64000){
cout << setw(w4-1)<<"$" <<((gross_income-16000)*tax_rate_1+ 1600); }
else {
if (marital_status==2 && gross_income > 64000){
cout << setw(w4-1)<<"$" <<((gross_income-64000)*tax_rate_2+ 8800 );}
}
}
cout<<endl;
cout<< setw(w1) << left << firstname <<endl;
cout<<endl;
system("pause");
return 0;
}
This is my code. I need help setting up the table so instead of the marital status being 1 or 2 it would read single or married. If you find any error feel free to correct me im a newbie.
Oct 2, 2011 at 2:09am UTC
Firstly, PLEASE, PLEASE use code tags, it really does make it easier to read. As for your question, I'm not sure quite what you mean, though couldn't you just either use enums or a couple of if statements?