PayStub Input/OutPut

I am trying to get an infile/outfile code for the following. According to my professor I need a ReadInputData, CalculateGrossPay, CalculateTaxPay, CalculateNetPay, WriteOutputData. I know I have to separate some of algorithms. I also not sure if I got the 401k correct. Any help?

//The Payroll Calculator program to enter specific data
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;

//Function prototypes
void GetData(ifstream& In, string& empId, double& empName, double& grossPay, double& FIT, double& FICA,
double& SIT, double& insDeduct, double& cont401k, double& netPay);

//Prints out the employee's pay stub
void PrintResult(string empId, double empName, double grossPay, double FITrate, double FICArate,
double SITrate, double insDeduct, double cont401k, double netPay);

//Tax Rate by Code...
const double FICArate = 0.062;
const double FMEDrate = 0.0145;
const double SITrate = 0.05;
const double FITrate = 0;
//Paycode by rate...
const double Mrate = 27.50;
const double Crate = 19.50;
const double Lrate = 10.35;
//Insurance Code
const double Acode = 25.00;
const double Bcode = 15.00;
const double Ccode = 0.00;
//Tax Bracket for FIT
const double Bracket1 = 0.125;
const double Bracket2 = 0.22;
const double Bracket3 = 0.2935;
//Contribution to 401k set at $150 deduction from grosspay
const double cont401k = 150.00;

void main()
{
ifstream inFile;
ofstream outFile;

inFile.open("PayrollCalculator2_1.txt");
outFile.open("PayrollCalculator2_1.txt");

char exit = 'n';

while (exit == 'n')
{
//Variable declaration
string empName;
double empId = 0;
double hWorked = 0;
double hRate = 0;
double oTime = 0;
double grossPay = 0;
double cont401k = 0;
double insDeduct = 0;
double FIT = 0;
double FICA = 0;
double SIT = 0;
double FMED = 0;
double netPay = 0.0;
char employeeType;
char choice;

while (inFile.fail())
{
inFile >> hWorked;
//Check if input failure
if (inFile.fail());
}
inFile.clear();

inFile.ignore(255, '\n');
outFile << "you entered an invalid value! Please re-enter in correct format." << endl;

outFile.open("PayrollCalculator2_1.txt");

//Input information for Employee
outFile << "Enter Employee Name: ";
getline(inFile, empName);

outFile << "Enter Employee ID: ";
inFile >> empId;

outFile << "ENTER THE HOURS WORKED: ";
inFile >> hWorked;

outFile << "Enter Employee Type: ";
outFile << "M or m (a manager employee),";
outFile << "C or c (a contractor employee),";
outFile << "L or l (a level employee),";
inFile >> employeeType;

outFile << endl;
outFile << "A or a ($25.00 Insurance Deduction)," << endl;
outFile << "B or b ($15.00 Insurance Deduction)," << endl;
outFile << "C or c ($0.00 Insurance Deduction)," << endl;
inFile >> choice;

outFile << endl;

switch (employeeType)
{
//Manager Hourly Pay Rate
case 'm':
case 'M':
hRate = Mrate;
break;
//Contrator Hourly Pay Rate
case 'c':
case 'C':
hRate = Crate;
break;
//Level Hourly Pay Rate
case 'l':
case 'L':
hRate = Lrate;
break;
default:
hRate = Lrate;
}

if (choice == 'A')
insDeduct = 25.00;
if (choice == 'B')
insDeduct = 15.00;
if (choice == 'C')
insDeduct = 0.00;

//Caculates employee regular pay with overtime.
//The first 8 hours are calculated at hRate + 50%.
//Any hours beyond are double time + grosspay.
if (hWorked <= 40)
{
grossPay = (hRate * hWorked) - cont401k;
}

if (hWorked > 40 && hWorked <= 48)
{
grossPay = (40 * hRate) + (hWorked - 40)*(hRate*1.5)-cont401k;
}

if (hWorked > 48)
{
grossPay = 40 * hRate + 8 * 1.5 * hRate + (hWorked - 48) * 2.0 * hRate - cont401k;
}

if (grossPay > 0 && grossPay < 350.00)
FIT = (grossPay * Bracket1);

if (grossPay > 350.00 && grossPay < 1000.00)
FIT = (grossPay * Bracket2);


if (grossPay > 1000.00)
FIT = (grossPay * Bracket3);
else
{
break;
}

FICA = FICArate * grossPay;
FMED = FMEDrate * grossPay;
SIT = SITrate * grossPay;
insDeduct = choice - grossPay;

netPay = grossPay - FIT - FICA - FMED - SIT - insDeduct;



outFile << "----------------------------------------------------------" << endl;

outFile << "ID Name Gross FIT FMED FICA SIT 401k Ins Net" << endl << endl;
outFile << setw(6) << empId;
outFile << fixed << showpoint;
outFile << setw(10) << setprecision(2) << empName
<< setw(9) << setprecision(2) << grossPay
<< setw(7) << setprecision(2) << FIT
<< setw(6) << setprecision(2) << FICA
<< setw(6) << setprecision(2) << FMED
<< setw(6) << setprecision(2) << SIT
<< setw(5) << setprecision(2) << cont401k
<< setw(8) << setprecision(2) << insDeduct
<< setw(9) << setprecision(2) << netPay
<< endl;
outFile << endl;
outFile << "--------------------------------------------------" << endl;

//Loop termination
outFile << "Do you want to exit (n/y)" << endl;
inFile >> exit;
}
inFile.close();
outFile.close();

return;
}
Last edited on
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your
post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <>
formatting button.
closed account (48T7M4Gy)
This is a double post - please don't
Topic archived. No new replies allowed.