I've been working on this programming assignment this past week and I'm just stumped.
Probably something simple and stupid that I missed since I tend to do that and this
past week was rediculously busy (taking 5 classes this semester)
Anyway, here's the contents of the "payroll.txt" file accessed in the following program:
Quote
John Smith#10.45 40 15
Jane Doe#12.50 45 15
Harry Morgan#20.00 40 20
Carmen Martinez#25.00 35 25
Jacintha Washington#50.85 60 35
Jane Doe#12.50 45 15
Harry Morgan#20.00 40 20
Carmen Martinez#25.00 35 25
Jacintha Washington#50.85 60 35
And here's what I have as far as code goes. I'm sure my math for the processPay function is wrong.
And I'm also sure something else is screwed up since it only seems to output 1 line.
Help!
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
void reportDescription();
void reportTitle();
void inputData(ifstream& inFileData, string& name, double& pay, double& time, double& tax);
void processPay(double payrate, double hours, double tax, double& grossPay, double& netPay, double& grossTotal, double& netTotal);
void printEmployeeInfo(string name, double pay, double time, double tax, double gross, double net);
void totalAmounts(double totalGross, double totalNet);
int main()
{
string empName;
double payRate;
double hoursWorked;
double taxRate;
double grossPay;
double netPay;
double grossPayTotal;
double netPayTotal;
ifstream inFileData;
inFileData.open("c:\\payroll.txt");
reportDescription();
reportTitle();
while (!inFileData.eof())
{
inputData(inFileData, empName, payRate, hoursWorked, taxRate);
}
inFileData.close();
processPay(payRate, hoursWorked, taxRate, grossPay, netPay, grossPayTotal, netPayTotal);
printEmployeeInfo(empName, payRate, hoursWorked, taxRate, grossPay, netPay);
totalAmounts(grossPayTotal, netPayTotal);
return 0;
}
void reportDescription()
{
cout << "This program calculates paychecks for each employee. "<< endl
<< "A text file will be created outside of the program with the information: "<< endl
<< "name, rate of pay, number of hours worked, and tax percentage to be deducted." << endl
<< endl
<< "The program will create a report in columnar format showing the employee "<< endl
<< "name, hourly rate, number of hours worked, tax rate, gross pay, and net pay. "<< endl
<< endl
<< "After all employees are processed, totals will be displayed total gross amount "<< endl
<< "and total net pay." << endl
<< endl << endl;
}
void reportTitle()
{
cout << setfill(' ') << right << setw(38) << "Payroll Report" << endl;
}
void inputData(ifstream& inFileData, string& name, double& pay, double& time, double& tax)
{
getline(inFileData, name, '#');
inFileData >> pay >> time >> tax;
inFileData.ignore(100, '\n');
}
void processPay(double payrate, double hours, double tax, double& grossPay, double& netPay, double& grossPayTotal, double& netPayTotal)
{
double temptax = netPay * tax;
netPay = payrate * hours;
grossPay = netPay - temptax;
grossPayTotal = grossPayTotal + grossPay;
netPayTotal = netPayTotal + netPay;
}
void printEmployeeInfo(string name, double pay, double time, double tax, double gross, double net)
{
cout << fixed << showpoint << setprecision(2);
cout << left << setw(20) << "Employee" << setw(10) << "Hourly" << setw(10) << "Hours" << setw(10) << "Tax" << setw(10) << "Gross" << setw(10) << "Net" << endl;
cout << left << setw(20) << "Name" << setw(10) << "Rate" << setw(10) << "Worked" << setw(10) << "Rate" << setw(10) << "Amount" << setw(10) << "Amount" << endl;
cout << endl;
cout << left << setw(20) << name << setw(10) << setw(10) << pay << setw(10) << time << setw(10) << tax << setw(10) << gross << setw(10) << net << endl;
}
void totalAmounts(double totalGross, double totalNet)
{
cout << left << setw(5) << "Totals" << right << setw(10) << totalGross << setw(10) << totalNet << endl;
}

New Topic/Question
Reply




MultiQuote






|