View Single Post
Counting a while loop?
Junior Member
Status: Offline
Posts: 1
Join Date: Jun 2012
Default Counting a while loop? - 06-27-2012, 06:30 PM

Hi all, New Alice user here... I must say fantastic program for introductions to java! Started Uni studies and this is our first stepping stone in programming.

Anyway I have the following problem, Iam required to build an interest calculator. The calculator gets 3 values from the user (initial balance, target balance, interest rate) it then performs the math and outputs yearly the new total balance.

I have it working by using a while loop that executes if the current balance is =< target it will do the math.. Update the current balance, prints the balance and does the check again and keeps going over n over... As it should until it's => target.

My problem lies in that right before I print the current balance in each loop I also want a counter to display what year it is (eg 1 thru to whatever not the actual year) so that you can see how many years elapsed to achieve your goal.

I have tried a normal loop and printing the index.. Did not work as I couldn't tell the loop when to stop as that variable changes
Tried a couple of other things as well but does anybody have any suggestions?

Hesitant to post up the code as this is an assignment so Iam after a nudge in he right direction rather than a solution?

Iam thinking maybe there is a way to creat a new method variable that updates each cycle through and print that? Warm?

Thanks everyone
Reply With Quote