Im working on a program and I am somewhat stuck on one of the functions. I am trying to read in bank accounts and perform operations on them. I want to pay interest to accounts with a positive savings, move negative savings to credit and charge interest, and charge interest on positive credit balances. The program requires a file called a1.txt to read in values.
a1.txt contains the following values:
Jim 23.41 0
Bob 58.32 0
Sally -1.34 0
My problem is this, when I run the program I can get only Sally to calculate. The first two arent outputting. I think it has something to do with my while (line 80) loop calculations but I can't figure out what it is. Any insight would be appreciated. Here is the code.
My read here is that since the output on line 107 is outside the while loop, it only gets called once after the third record (Sally) has been read in and processed. So the variables for name, savings and credit are holding Sally's info. The info for the previous accounts is overwritten with every loop through the while structure.
I'd try moving the output line into the while loop at the end, so you write out the results of the current account before reading in a new line and overwriting data.