So I have a program that has linked lists and queue. In the text file the S is a sale, the P a promotion and R a receipt. What I want my program to do is to insert the R widgets into a queue and if the the next item is an S widget to subtract the the number of the sale from the number in the queue. If the number in the queue becomes negative then I want the program to pop the front of the queue and take that negative number and subtract from the next item in the queue. The problem comes up when I get to the second sale. For some reason I think the continue; statement is going to the next iteration of the for loop instead of the while loop and setting everything out of whack. What is going wrong?
Thanks.
R 150 1.00
R 130 2.00
S 145
R 50 2.50
S 75
S 180
R 50 4.00
R 30 5.00
R 40 5.50
P 30
S 50
S 30
R 50 6.00
R 265 10.00
S 60
P 50
S 100
S 70
S 175
R 40 14.00
R 75 15.00
S 110
R 30 16.00
R 40 18.00
Now I fixed it. As for the continue statement, I know it shouldn't be possible. It could be the line 74 if statement but so far my tracing hasn't come up with problems yet.
On each iteration of for loop only one value gets pushed in num queue
Before continue you have num.pop(); which removes only element from it. So continue will force next iteration, !num.empty() returns false and while loop terminates.
Rest of for loop is executed and next iteration begins.
Now I believe that the problem lies with the condition of the while loop because in the while loop !num.empty() means that it will keep printing until the the queue is empty. So far of the conditions I used worked.
So I took out the continue statement because it just wasn't working. I also changed the conditions of the while loop a little. I almost have it but it's still not working 100%. Any suggestions?
Thanks.