You should hurry up and do this.

Driving test 3 is only worth a small handful of points now, so I figured it’s about time I did it.

Pick out the features we need to have:

  • User needs to be able to enter their current balance, how much they want to pay off, and their interest rate
  • Then a list box needs to be updated showing a month by month snapshot of their account
  • Calculate how long it’ll take to pay off their debt

So it’s pretty obvious what we need to set up:

This is just how I've done it; be more inventive!

This is just how I've done it; be more inventive!

Remember to do validation on all three inputs, and give errors when there’s problems:

  • They need to be greater than zero
  • The need to be a numbers
  • It can’t be blank!

Before you start outputting to the list box, you need to make sure that the user will actually eventually pay off their loan. The biggest problem I think they are having with this test is that they’re not testing to see if their loop actually ever finishes. To start with, you have to make sure that the user is paying more every month than is added to their loan due to interest.

If the user is paying £10 a month, but the interest is £11 a month, they’ll never pay off the loan.

InterestAmountEachMonth = TotalBalance + (TotalBalance * InterestRate)
If InterestAmountEachMonth > MonthlyPayment Then Error

Check for that first. Then give an error. If they are paying off enough though you can start taking it off their balance! Do something like this:

While TotalBalance > 0 Then
  TotalBalance = TotalBalance - Payment + Interest
  Update Listbox With New Balance
End While

You have to output what month number it is as well!

That’s pretty much it. Remember to do a test plan like last time too.

Things you should think about:

  • Make it so the total amount owed never goes below zero (you wouldn’t pay more than you had to, would you?)
  • Clear the list box when you do another calculation
  • Put the validation into a function
  • Make all the currencies output with the right decimal places, and with a £ sign. (Use .ToString (“c”))
  • Why’re you using a while loop, and not a for loop?

Comments are closed.