not all 5 lines are read from my text file

Hello, this is my first programming class and I had to create a program as explained below, with the data provided as shown below the instructions. I think I have all the bases covered, except that the last line of data is not shown for the 5th person, only for the first four lines. Would you please help with how I can make sure all 5 lines of data are read? Thank you for your time!

instructions:
Write a program that will read the payroll file. It should output the name and paycheck amount to the console. Also output the total pay of all employees to a data file "totals.dat". The input file contains the name followed by hourly wage followed by hours worked.

data:
Bones_Bob 10.50 40
Smith_Sally 11.25 40
Toll_Tom 8.10 35
Anderson_Ann 7.25 20
Carlson_Carl 9.75 22

my output:
Employee: Bones_Bob | Gross Pay: 420.00
Employee: Smith_Sally | Gross Pay: 450.00
Employee: Toll_Tom | Gross Pay: 283.50
Employee: Anderson_Ann | Gross Pay: 145.00


[code]
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <iomanip>

using namespace std ;

int main()
{
ifstream employee_in ;
ofstream writer("totals.dat") ; //professor requested .dat
string name ;
double payRate, hrsWorked, grossPay ;
employee_in.open ( "payroll.txt" ) ; //open file
employee_in >> name ; //read field
employee_in >> payRate ; //read field
employee_in >> hrsWorked ; //read field

if (!employee_in.is_open())
{
cout << "Failure to open file" << endl ;

return 0 ;
}

while (!(employee_in.eof()))
{
grossPay = (payRate * hrsWorked) ; //calculate gross
writer << grossPay << endl ;
cout << fixed << setprecision (2) ;
cout << "Employee: " << name << " | Gross Pay: " << grossPay << endl ;
getline(employee_in,name) ;
employee_in >> name >> payRate >> hrsWorked ;
}

employee_in.close() ;


return 0 ;
}
Hello,

Just wanted to say, thank yal, I kept trying and got it worked out. Yet, I am thankful for this forum, very helpful and insightful are the posts and replies. Have a great weekend yal!
Topic archived. No new replies allowed.