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

I just need help setting the table. I have an issue with getting the martial status from 1 or 2 to actually saying single or married on the table. If you find any errors feel free to correct me, Im a newbie. Thanks.

Something like this:

const std::string SINGLE = "Single" ;
    const std::string MARRIED = "Married" ;
    const std::string INVALID = "??????" ;
    
    if( marital_status == 1 ) std::cout << SINGLE ;
    else if( marital_status == 2 ) std::cout << MARRIED ;
    else cout << INVALID ;

Alternatively, use a switch-case.

You need to: #include <string> and also perhaps validate user input.

Thank You!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.