#include <iostream>
#include <fstream>

using namespace std;

int main() {
    int numberofemployees;
    int employeeid, hoursworked;
    float hourlyrate, grosspay, taxamount, netpay;
    const float TAXRATE=0.10;
    ifstream fin("C:\Dev-CPP\employee.txt");
    
    while (!fin.eof() )}
          fin >> employeeid >> hoursworked >> hourlyrate;
          cout<<"EMPLOYEE ID IS: "<<employeeid<<endl;
          cout<<"THE HOURS WORKED ARE: "<<hoursworked<<endl;
          cout<<"THE HOURLY RATE IS: "<<hourlyrate<<endl;
          grosspay=hoursworked*hourlyrate;
          taxamount=grosspay*TAXRATE;
          netpay=grosspay-taxamount;
          cout<<"THE GROSSPAY IS"<<grosspay<<endl;
          cout<<"THE TAX AMOUNT IS"<<taxamount<<endl;
          cout<<"THE NETPAY IS"<<netpay<<endl;
}

          fin.close ();
// system("pause");
   return 0;
}//MAIN

- Using Bloodshed Dev C++ -
The name of the project sourcefile is payollin.cpp and document employee.txt
are in same folder (C:\Dev-Cpp).

You need to explain what problem you have with this code. Also it should be

[code=cplusplus]

"C:\Dev-CPP\employee.txt" may not correct , do not you need escape \ using \\ ?

It would be good if you could tell us what problems you're facing. So i'm presuming that employee.txt is an infile? Please upload it.

#include <iostream>
#include <fstream>

using namespace std;

int main() {
    int numberofemployees;
    int employeeid, hoursworked;
    float hourlyrate, grosspay, taxamount, netpay;
    const float TAXRATE=0.10;
    ifstream fin("C:\Dev-Cpp\employee.txt");

    while (!fin.eof()){
          fin >> employeeid >> hoursworked >> hourlyrate;
          cout<<"EMPLOYEE ID IS: "<<employeeid<<endl;
          cout<<"THE HOURS WORKED ARE: "<<hoursworked<<endl;
          cout<<"THE HOURLY RATE IS: "<<hourlyrate<<endl;
          grosspay=hoursworked*hourlyrate;
          taxamount=grosspay*TAXRATE;
          netpay=grosspay-taxamount;
          cout<<"THE GROSSPAY IS"<<grosspay<<endl;
          cout<<"THE TAX AMOUNT IS"<<taxamount<<endl;
          cout<<"THE NETPAY IS"<<netpay<<endl;
}//WHILE
   return 0;
}//MAIN      



ihe infile is employee.txt, here is file......

9380    35     18.00
0450    42     16.00
7834    45     10.00
4319    27     22.00
8899    40     18.00

when I compile and run it does not stop![code=cplusplus]


#include <iostream>
#include <fstream>


using namespace std;


int main() {
int numberofemployees;
int employeeid, hoursworked;
float hourlyrate, grosspay, taxamount, netpay;
const float TAXRATE=0.10;
ifstream fin("C:\Dev-Cpp\employee.txt");


while (!fin.eof()){
fin >> employeeid >> hoursworked >> hourlyrate;
cout<<"EMPLOYEE ID IS: "<<employeeid<<endl;
cout<<"THE HOURS WORKED ARE: "<<hoursworked<<endl;
cout<<"THE HOURLY RATE IS: "<<hourlyrate<<endl;
grosspay=hoursworked*hourlyrate;
taxamount=grosspay*TAXRATE;
netpay=grosspay-taxamount;
cout<<"THE GROSSPAY IS"<<grosspay<<endl;
cout<<"THE TAX AMOUNT IS"<<taxamount<<endl;
cout<<"THE NETPAY IS"<<netpay<<endl;
}//WHILE
return 0;
}//MAIN

ihe infile is employee.txt, here is file......

9380    35     18.00
0450    42     16.00
7834    45     10.00
4319    27     22.00
8899    40     18.00

when I compile and run it does not stop!

You need a (/code) at the end of your statements.

refer to what ithelp said above. You need to escape your \ inside the quotes, so your file name string probably needs to be "C:\Dev-Cpp\employee.txt"

Also it is better to explicitly state the mode in which you want to open the file, and then check if the file pointer is valid or not before proceeding to try and read the contents of your file.

ifstream ifs ( "test.txt" , ifstream::in );

if(ifs.good()) { // we have a valid pointer, proceed

................
}

Hey, Are you sure that the file is being opened?
Because Your Code Doesnt Test whether it has opened it

if (myfile.is_open()) { /* ok, proceed with output */ }

You should have an if statement like the above to know that you have opened the file successfully.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.