Here is the code. Ignore the commented out code.
Basically I am trying to pull items from a text file and assign them to the hourlyEmp1 through hourlyEmp3 items.
This is what the txt file looks like:
Caleb
21
40 0 40 0 40 0 40
John
16
40 0 40 0 40 0 40
Jason
15
40 0 40 0 40 0 40
I can get Calebs information assigned to hourlyEmp1MonthlyGrossPay, but then it stops at that.
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
double getInfoOneEmp(ifstream &inFile, string& tempName, const int& WEEKS);
void employeeOutput(ofstream& outFile, const string& tempName, const double& tempGrossPay);
int main() {
string hourlyEmp1 = " ", hourlyEmp2 = " ", hourlyEmp3 = " ";
const int WEEKS = 4;
double hourlyEmp1MonthlyGrossPay, hourlyEmp2MonthlyGrossPay, hourlyEmp3MonthlyGrossPay;
double regHours, ovtHours, wageRate, totalPay;
ifstream payrollInFile;
ofstream payrollOutFile;
int totalEmp = 4;
payrollInFile.open("input.txt");
payrollOutFile.open("output.txt");
hourlyEmp1MonthlyGrossPay = getInfoOneEmp(payrollInFile, hourlyEmp1, WEEKS);
payrollInFile.ignore(100, '
');
employeeOutput(payrollOutFile, hourlyEmp1, hourlyEmp1MonthlyGrossPay);
hourlyEmp2MonthlyGrossPay = getInfoOneEmp(payrollInFile, hourlyEmp2, WEEKS);
payrollInFile.ignore(100, '
');
employeeOutput(payrollOutFile, hourlyEmp2, hourlyEmp2MonthlyGrossPay);
hourlyEmp3MonthlyGrossPay = getInfoOneEmp(payrollInFile, hourlyEmp3, WEEKS);
payrollInFile.ignore(100, '
');
employeeOutput(payrollOutFile, hourlyEmp3, hourlyEmp3MonthlyGrossPay);
payrollInFile.close();
payrollOutFile.close();
/*for(int i = 0; i <= totalEmp; i++) {
while (i <= totalEmp) {
string answer;
cout << "Would you like to enter tips for " <<hourlyEmp1<< " ?"<<endl;
if(answer="y") {
for(int x = 0; x <=WEEKS; x++) {
while(x <= WEEKS) {
cout<<"Please enter week: " << x + 1 << "tips:"<<endl;
}
}
}
}
}*/
}
double getInfoOneEmp(ifstream &inFile, string& tempName, const int& WEEKS)
{
double regHours, ovtHours, wageRate, totalPay, MonthlyPay = 0;
getline(inFile, tempName);
inFile >> wageRate;
for (int counter = 0; counter < WEEKS; counter++)
{
inFile >> regHours >> ovtHours;
totalPay = (regHours * wageRate) + (ovtHours * wageRate * 1.5);
MonthlyPay = MonthlyPay + totalPay;
}
return MonthlyPay;
}
/*void getEmployeeInfo(ifstream &inFile, string&tempName, double &tempWage) {
}*/
void employeeOutput(ofstream& outFile, const string& tempName, const double& tempGrossPay)
{
outFile << fixed << showpoint << setprecision(2);
outFile << "Total Pay for " << tempName << " for the month is $" << setfill('*') << setw(10)
<< tempGrossPay << setfill(' ') << endl;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…