#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
ifstream PayrollDoc;
PayrollDoc.open("hours.txt");
string line;
int counter = 0;
string Name, WorkerID;
float Hours, Wage, Paycheck;
if (PayrollDoc.is_open())
{
while (!PayrollDoc.eof())
{
if (counter == 0)
{
getline(PayrollDoc, Name);
counter++;
}
else if (counter == 1)
{
getline(PayrollDoc, WorkerID);
counter++;
}
else if (counter == 2)
{
std::istringstream PayrollDoc(line);
cin >> Hours;
counter++;
}
else if (counter == 3)
{
std::istringstream PayrollDoc(line);
cin >> Wage;
counter++;
}
else if (counter == 4)
{
Paycheck = Hours * Wage;
cout << Name << WorkerID << Paycheck << endl;
counter = 0;
}
}
}
else
{
cout << "The specified file could not be found.";
}
return 0;
}
And the text file looks like this:
A00115
John Doe
36.5
25.0
A01256
Jane Doe
40.0
28.0
My compiler is not giving me any errors, but gives no output and I am quite truly stumped. It should output the Name, ID number, and paycheck amount on one one line. I am confused as how to use getline for floats, any help would be very appreciated.