954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Any help with C++ payroll! -noob

#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).

hapiscrap
Light Poster
26 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

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

[code=cplusplus]

stilllearning
Posting Whiz
309 posts since Oct 2007
Reputation Points: 161
Solved Threads: 43
 

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

ithelp
Nearly a Posting Maven
Banned
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128
 

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.

zandiago
Nearly a Posting Maven
2,480 posts since Jun 2007
Reputation Points: 129
Solved Threads: 26
 

[code=cplusplus]

#include
#include

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: "<

hapiscrap
Light Poster
26 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

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

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

stilllearning
Posting Whiz
309 posts since Oct 2007
Reputation Points: 161
Solved Threads: 43
 

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.

Sky Diploma
Practically a Posting Shark
865 posts since Mar 2008
Reputation Points: 673
Solved Threads: 131
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You