Please help if you can!

Pages: 12
If you want my honest opinion, you should be using the Shelve library in Python to handle a task like this, NOT c++.
(fin>>employeeid>>hoursworked>>hourlyrate)

That line stores data from fin into the variables employeeid, hoursworked, hourlyrate. If you had anything in there before (which you did - you're using them to store the user's input), that previous data is overwritten.

employeeid != 1234, 5678, 9098, 7654, 3210
That's just a complete misunderstanding of what the , syntax dies. Don't use it. It does not mean what you think it means here.

Moschops, I was thinking along those lines last night. I tried removing the employeeid from the fin statement to see if that worked, but I got the same result.

(fin>>hoursworked>>hourlyrate)

Is that how it should read? Am I missing something else?

And slurpee123abc, since it is a C++ Course, I doubt doing it in Python will help me :p
Last edited on
(fin>>hoursworked>>hourlyrate)

That won't do you much good, given that the text file contains the employee numbers. They will still be read in.

I think you might find things a bit easier to think about if you have two variables; employeeNumberToFind and employeeNumber. The first will be provided by the user, the second read in from the text file.
Well I have been following up the exchange here and I figure what Moschops trying to tell you and you probably getting it at the same time you probably don't even have enough time to work on this.

This code could do most of the work except one thing missing and that is instead of matching the first 4 digit of the line with the user input try to match it with the whole line. You probably could figure that out, i will c if i could work on it and update u.... don't count on me though

#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <sstream>

using namespace std;


int main()
{
int id;
float hoursworked, hourlyrate, grosspay, taxamount, netpay;
float const TAXRATE = 0.30;

cout << "PLEASE ENTER THE EMPLOYEE NUMBER: ";
cin >> id;
cout << endl;

ifstream fin;
string line = " ";
int x = 0, empid;

fin.open("employee.txt");
if (!fin)
{
cout << "Unable to open the file\n";
// exit(1);
}

else
{
while(fin.good())
{
while(getline(fin, line))
{

cout <<"this is the line: "<< line << endl;
if(empid == id)
{
stringstream fin(line);
fin >> empid >> hoursworked >> hourlyrate;
grosspay = hoursworked * hourlyrate;
taxamount = grosspay * TAXRATE;
netpay = grosspay - taxamount;

cout<<"YOUR EMPLOYEE ID: " << setw(6) << setprecision(4) << empid <<endl;
cout<<"YOUR HOURS WORKED: " << setw(5) << setprecision(4) << hoursworked <<endl;
cout<<"YOUR HOURLY RATE: " << setw(1) << setprecision(6) << "$" << hourlyrate <<endl;
cout<<"YOUR GROSS PAY: " << setw(5) << setprecision(6) << "$" << grosspay << endl;
cout<<"YOUR TAX AMOUNT: " << setw(4) << setprecision(6) << "$" << taxamount << endl;
cout<<"YOUR NET PAY: " << setw(7) << setprecision(6) << "$" << netpay <<endl;
}
else cout << "INCORRECT EMPLOYEE ID";
fin.close();
cout <<endl;
cout <<"This is line # "<< x << "\t" << line << endl;
cout <<endl;

++x;

}//WHILE
fin.close();
}
cin.get();
}


return 0;
} //MAIN
Actually, abiyek, I have been working on this since I read Moschops last post earlier this afternoon, and I haven't had time to come back and check for any other replies. But, I sincerely thank you for your input. That phase of the program ended up looking pretty much just like yours. It was great figuring it out with helpful hints, rather than just getting the answer fed to me. But, trust me, I was nervous I wasn't going to finish in time. Too bad you weren't around here yesterday! Just kidding :p Thanks a lot!

And Moschops, I really appreciate your continued attention. Your replies really helped me to finish this assignment by actually figuring out what I was doing wrong, so thank you very much!
Topic archived. No new replies allowed.
Pages: 12