We help IT Professionals succeed at work.
Get Started

Why does (!file.eof()) cause repeat of last input

mike9380 asked
Last Modified: 2012-08-13
The last line of input doubles in output  in the Bloodshed Dev-C++ compiler.

The input file is (employee.txt):

7453    40     18.00
1049   38     32.00
6734    39     22.00
4545    40     24.00
9707   38     35.00


#include <iostream> 
#include <fstream>
using namespace std;
int main() 
    int numberofemployees;
    int employeeid, hoursworked;
    float hourlyrate, grosspay, taxamount, netpay;
    const float TAXRATE=0.10;
    std::ifstream fin("employee.txt");
    while (!fin.eof() )
          fin >> employeeid >>hoursworked >> hourlyrate;
          std::cout<<"THE EMPLOYEE ID IS: "<<employeeid<<endl;
          std::cout<<"THE HOURS WORKED ARE: "<<hoursworked<<endl;
          std::cout<<"THE HOURLY RATE IS: "<<hourlyrate<<endl;
          std::cout<<"THE GROSSPAY IS: "<<grosspay<<endl;
          std::cout<<"THE TAX MOUNT IS: "<<taxamount<<endl;
          std::cout<<"THE NETPAY IS: "<<netpay<<endl;
          fin.close ();
          getchar ();
          return 0;

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE