Any help with C++ payroll! -noob

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 26
Reputation: hapiscrap is an unknown quantity at this point 
Solved Threads: 0
hapiscrap hapiscrap is offline Offline
Light Poster

Any help with C++ payroll! -noob

 
0
  #1
Oct 6th, 2008
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int numberofemployees;
  8. int employeeid, hoursworked;
  9. float hourlyrate, grosspay, taxamount, netpay;
  10. const float TAXRATE=0.10;
  11. ifstream fin("C:\Dev-CPP\employee.txt");
  12.  
  13. while (!fin.eof() )}
  14. fin >> employeeid >> hoursworked >> hourlyrate;
  15. cout<<"EMPLOYEE ID IS: "<<employeeid<<endl;
  16. cout<<"THE HOURS WORKED ARE: "<<hoursworked<<endl;
  17. cout<<"THE HOURLY RATE IS: "<<hourlyrate<<endl;
  18. grosspay=hoursworked*hourlyrate;
  19. taxamount=grosspay*TAXRATE;
  20. netpay=grosspay-taxamount;
  21. cout<<"THE GROSSPAY IS"<<grosspay<<endl;
  22. cout<<"THE TAX AMOUNT IS"<<taxamount<<endl;
  23. cout<<"THE NETPAY IS"<<netpay<<endl;
  24. }
  25.  
  26. fin.close ();
  27. // system("pause");
  28. return 0;
  29. }//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).
Last edited by Narue; Oct 7th, 2008 at 3:41 pm. Reason: fixed code tags
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 305
Reputation: stilllearning has a spectacular aura about stilllearning has a spectacular aura about 
Solved Threads: 43
stilllearning stilllearning is offline Offline
Posting Whiz

Re: Any help with C++ payroll! -noob

 
0
  #2
Oct 6th, 2008
You need to explain what problem you have with this code. Also it should be

[code=cplusplus]
Last edited by stilllearning; Oct 6th, 2008 at 6:25 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,824
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 117
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: Any help with C++ payroll! -noob

 
0
  #3
Oct 7th, 2008
"C:\Dev-CPP\employee.txt" may not correct , do not you need escape \ using \\ ?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2,462
Reputation: zandiago is on a distinguished road 
Solved Threads: 25
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

Re: Any help with C++ payroll! -noob

 
0
  #4
Oct 7th, 2008
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.
I shot the sheriff....but I didn't shoot the deputy
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 26
Reputation: hapiscrap is an unknown quantity at this point 
Solved Threads: 0
hapiscrap hapiscrap is offline Offline
Light Poster

Re: Any help with C++ payroll! -noob

 
0
  #5
Oct 7th, 2008
[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!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 305
Reputation: stilllearning has a spectacular aura about stilllearning has a spectacular aura about 
Solved Threads: 43
stilllearning stilllearning is offline Offline
Posting Whiz

Re: Any help with C++ payroll! -noob

 
0
  #6
Oct 7th, 2008
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

................
}
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 672
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 99
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster

Re: Any help with C++ payroll! -noob

 
0
  #7
Oct 7th, 2008
Hey, Are you sure that the file is being opened?
Because Your Code Doesnt Test whether it has opened it

  1. 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.
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC