I am buidling a payroll tracker and need help

As stated above my ultimate goal is to build a payroll tracker that when i run the program it asks me how many hours i worked stores that to a variable in a txt file for later retrieval. at the end of the payroll cycle I want the application to total my hours and add the correct multiplier to calculate my payroll. I know i know just use a calculator and be done with it. I am trying to learn how to do some basic coding in c++ so that is my project. My problem I am experiencing is if use ofstream when i go to pass the data back i get an error saying variable declared as ofstream. this may be covered somewhere else in the forums and ill be honest i havent looked through them all yet .. i know how to make the basic calc functions the problem i have is storing and retrieving the appropriate data. FYI I have a few jobs and different pay rates for each job so thats why i was trying to make something like this .. any help would be greatly appreciated and if i am being to vague please ask me specifics needed to help :) thnx folks in advance.
Last edited on
just to give an idea this is the code im trying to use to put int x in a txt file and recall it the comments you see are for me when i get further in my project...
int main(){

ofstream workfile ("work file.txt");
int X = 5;

cout << X <<endl;
X= X + 4;
workfile << X;

workfile >> X;

cout << "X =" << X << endl;
//worktracker WO;
// WO.print();


workfile.close();

// return 0;
}

this is the error that i get running this code
std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<char, _Traits>'
workfile >> X;

after playing around with my code i answered my first question listed above however i have a new one now.. I can send a value to a file and save it and i can now even recall that saved data however now that i got all that i am having a problem of making the file store more then one run of the app for example i can save the data entered on first run but now when i run a second time the file only retains the data from second run. is there a way to store data to a file and have it remember all data after several runs .. example
day 1:
cout<< "how many hours did you work for today ?"
cin >> tothours
workfile<<tothours
cout << " how many hours with company x? "
cin>> xhours
workfile<<xhours
cout << "and how many hours for y? "
cin >> "y hours"
workfile<<yhours.
day 2: etc...the end result being

day 1 - day 14
cout <<totweekhours
cout "payroll = "
sorry for the long comments just trying to figure this out alright folks im outtie for now :)






to keep a running total of hours make sure to put
totalHours = totalHours + tothours;
after every time your program allows you to input your hours.
you will also have to initialize the totalHours = 0 that way everything is accurate.

you will have to do this for every input type since you're not using any modules or loops.
just vary the variables in the total calculations. for ex totalHoursX and totalHoursY.

As far as the error I can't help you with that because I didn't know it was possible to call a .txt. In order to keep calling this information I would use a function.


I hope this helped in some way. I'll try to keep helping you as much as I can.
I agree with all your suggestions and have already zeroed out the variables and was planning to use a new variable to store the total hours. However the big problem I am having is after running the program 2 x the file only shows the most recent run of the program I cannot figure out how to make it store day 1 and then next time I run it store day 1 and day 2 instead of just storing last input. Also I realized that I had not solved my original question of how to access the date stored in the text file. I have tried to use of stream and ifstream in same application but code blocks reports I cannot do that... I think it could very well be impossible what I am trying.
So I learned something new in class the other day and I really think it could help you. The only thing is youyr going to have to do some reading. Use this website to learn how to run loops and how to use arrays. arrays let you store any amount of values to one variable by adding a subscript. by running the loop it will allow you to control how many time you will run the array.
Topic archived. No new replies allowed.