I'm new to using c++ and I have to design and code a C++ program that utilizes a function to calculate the following for each employee from the time record input file employeehours.txt. I'm using void and calling the file on my device. However, I have duplicated code inside the void and in the main function and I don't know how to resolve it. This is what I have so far...
Can you be a bit more specific as to what the problem is?
It's also hard to diagnose your issue because there we don't know what your file looks like, or what your expected output is.
I'm only guessing what your problem is because you didn't really tell us what it is.
But, look at your total variable.
It is assigned 0 in line 19. Then you calculate and print out gp, tax and net based on that value in line 24 - 28. Then you set it to 0 and increment it by the value derived from hour.
The next time through the loop (line 20) you have total containing the value from the previous line's hour field.
I suspect you want to set total based on the hours in the current line. Maybe remove lines 31 and 32 and add total = stod(hour); after line 22.