I haven't read the calculations for correctness, but the flow of your program seems to rely on the value of i which never changes, I'm guessing by design... and I see LoanBalance is never changed in...