I am writing a payroll program that pulls information from a file, calculates pay and taxes, and outputs that information to the console. For some reason I cannot get the program to perform any calculations. I tried adding braces where I thought they were needed and my program crashed because variables weren't initialized. When I assigned values to them (0) it simply did the multiplication with zeroes instead of reading info from the file. I verified that it is opening the file. Any help would be greatly appreciated. I am really struggling with this program. Here is an example of my text file. Values are: empID, paycode, hours, rate.
101456 H 20 6.57
100045 S 81994.12
100321 H 45 23.50
101987 H 39 15.76
100486 S 116935.65
1. Read about compound statements here: http://www.cplusplus.com/doc/tutorial/control/
2. fileIn >> empID, code; should be: fileIn >> empID >> code;
3. Where do you read in grosspay or hours and rate?
As I was taught the program moves from one value to the next in sequential order. So what I was going for was that if the code was H, the program would read the next two values as hours and rate. Which would then calculate the grosspay (line 50). Unfortunately I am very lost and can't seem to get this figured out. I tried some other things, but now my program is just going into an infinite loop and displays a seemingly random number. Here is where I think my problem lies, it wont seem to move on through the file.
Finally, thank you so much. I have one last minor question. I know this is asked all the time, but the FAQ's still have me a little confused. I have the
while (!fileIn.eof()) command but yet it is still processing the last line in my text file twice. What am I doing wrong?
Awesome, I really appreciate all the help that you've given me when you didn't have to. It worked great and now I have a better understanding of how reading files works than I had before (not to mention a working program). Thanks again have a good night...or morning depending on where you are.