• Post Reply Bookmark Topic Watch Topic
  • New Topic

Loop Compound Interest  RSS feed

 
Terry Khan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey I am having difficulty with a loop problem with compound interest.  I have the outer loop working properly. But the inner loop i Have difficultly with. Its supposed to have 4 output colums, in this order,  period, initial balance, periodic interest, and final balance. If you run the program i have the period and final balance working properly. But im stucking on writing the inner loops for initial balance and periodic interest, periodic interest is just the final balance of each period (-) minus the final balance of the last period. and the initial balance of each period is = equal to the final balance of the last. And help would be appreciatied. using hsa console. thanks in advance.



           
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

I find your loop setup a little confusing.  So you have the outer loop set up to iterate over 24 periods, from 1 to 24.  Your inner loop has a loop variable named initialBal and it will iterate over the values from 4 to 24.  Is that what you really want?  So, for period 1, you have initialBal going from 4 to 24 and you will ostensibly use all of these values to do some kind of calculation. Then when period goes to 2, initialBal will again cycle through the values 4 to 24, and again, you'll use the values period==2 and initialBal==[4 .. 24] to another set of calculations. Then when period goes to 3, you will again cycle initialBal from [4 .. 24]. This repeats until you get to period is 24, and again initialBal cycles from [4 .. 24].  That's a lot of calculations.  Is that what you're actually going for here?
 
Terry Khan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:Welcome to the Ranch!

I find your loop setup a little confusing.  So you have the outer loop set up to iterate over 24 periods, from 1 to 24.  Your inner loop has a loop variable named initialBal and it will iterate over the values from 4 to 24.  Is that what you really want?  So, for period 1, you have initialBal going from 4 to 24 and you will ostensibly use all of these values to do some kind of calculation. Then when period goes to 2, initialBal will again cycle through the values 4 to 24, and again, you'll use the values period==2 and initialBal==[4 .. 24] to another set of calculations. Then when period goes to 3, you will again cycle initialBal from [4 .. 24]. This repeats until you get to period is 24, and again initialBal cycles from [4 .. 24].  That's a lot of calculations.  Is that what you're actually going for here?


No what i need to do is create a new column inner loop, that displays the difference of the loop - the previous number. essentially the loop - minus previous loop number. And I need another column loop that will display the int loop as the 2nd value of the outer loop and so on until 25. I am not sure how to code this inner loops as colums.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Terry Khan wrote:No what i need to do is create a new column inner loop, that displays the difference of the loop - the previous number. essentially the loop - minus previous loop number. And I need another column loop that will display the int loop as the 2nd value of the outer loop and so on until 25. I am not sure how to code this inner loops as colums.

That description is enough to make anybody loopy. It's really hard to figure out what you want to do when you put it that way. Why don't you give us an example of the kind of output you expect to see and perhaps explain how the calculations on one line are based on the calculations of the previous line of output. That might be a little bit easier to understand.
 
Terry Khan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:
Terry Khan wrote:No what i need to do is create a new column inner loop, that displays the difference of the loop - the previous number. essentially the loop - minus previous loop number. And I need another column loop that will display the int loop as the 2nd value of the outer loop and so on until 25. I am not sure how to code this inner loops as colums.

That description is enough to make anybody loopy. It's really hard to figure out what you want to do when you put it that way. Why don't you give us an example of the kind of output you expect to see and perhaps explain how the calculations on one line are based on the calculations of the previous line of output. That might be a little bit easier to understand.



The picture is my desired output screen. with my initial outer loop i have the period and final balance. But i am sure how to do the loops for the initial balance and periodic interest.
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I can see how you would want a loop for the rows, one loop iteration for each row, but I'm not seeing why you want another loop.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need an inner loop. What you need is an accumulator to keep track of a running total.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!