Do it with tabs then:
Code:
#include <iostream>
#include <string>
#include <climits>
#include <iomanip>
using std::cin;
using std::cout;
using std::endl;
using std::numeric_limits;
using std::streamsize;
using std::string;
using std::ios;
//Optional function: depends on IDE. Remove if not needed. void wait_for_enter();
//Additional helper. Remove if not needed. void reset_istream();
//-- const double FEDERAL_TAX_RATE = .33;
const double STATE_TAX_RATE = 0.06;
const double MAX_HOURS = 1.5;
const double OVERTIME = 40.0;
int main(int argc, char *argv[])
{
char employeeNumber[64];
char employeeName[64];
double federalTax;
double grossPay;
double hoursWorked;
double regularPay;
double premiumPay;
double netPay;
double payRate; //stores employee's pay rate as a real number double stateTax;
//input data
cout << "Enter employee number:";
cin.getline( employeeNumber, sizeof( employeeNumber ));
cout << "Enter employee name:";
cin.getline( employeeName, sizeof( employeeName ));
cout << "Enter pay rate:";
cin >> payRate;
cout << "Enter hours worked:";
cin >> hoursWorked;
//calculations
grossPay = hoursWorked * payRate;
federalTax = grossPay * FEDERAL_TAX_RATE;
stateTax = grossPay * STATE_TAX_RATE;
netPay = grossPay - federalTax + stateTax;
// CalcPay computes wages from the employee's pay rate // and the hours worked, taking overtime into account if ( hoursWorked > MAX_HOURS )
{
grossPay = (MAX_HOURS * payRate) + (hoursWorked - MAX_HOURS) * payRate * OVERTIME;
}
else
{
grossPay = hoursWorked * payRate;
}
//output results
cout.setf(ios::fixed, ios::floatfield);
cout.precision( 2 ); //output 2 decimal places
cout << "================================================================================" << endl;
cout << "Employee\tHours\tPay\tRegular\tPremium\tGross\tNet\tFederal\tState"<<endl;
cout << "number\tname\tworked\tRate\tpay\tpay\tpay\tpay\ttax\ttax"<<endl;
cout << employeeNumber;
cout << '\t' << employeeName;
cout << '\t' << hoursWorked;
cout << '\t' << payRate;
cout << '\t' << regularPay;
cout << '\t' << premiumPay;
cout << '\t' << grossPay;
cout << '\t' << netPay;
cout << '\t' << federalTax;
cout << '\t' << stateTax;
cout << endl;
cout << "================================================================================" << endl;
reset_istream();
wait_for_enter();
return 0;
}
//--------------------------------------------------- void reset_istream()
{
if(cin.eof())
{
cin.clear();
}
else
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
}
//--------------------------------------------------- void wait_for_enter()
{
cout << "press <enter> to continue...";
// Reset failstate, just in case.
cin.clear();
string line;
getline( cin, line);
}