Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using for loops in calculations

 
Andrew Albers
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My problem is the fact that i cannot get the loop to properly run correctly to calculate the second half table which is displayed with Months on the left and CD Value on the right. I just need to be pointed in the right direction, i have spent a lot of time trying to figure this out. thanks for taking the time to look at my code.


 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you sure all of the formulas for percent yield, monthly yield are correct?
 
Andrew Albers
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the ones before the loop i know are correct, once i figure out how to properly loop the math part ill know if my the equation in the loop is correct. i believe it is though.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I think I see what you're trying to do here, for the loop part you want to print out the number of months from 1 to (whatever the user enters) right? Then you want to calculate how much money is gained on the cd per month and display it across from the month. is this right??
 
Andrew Albers
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup, then its prints out like:
Months
1
2
3
etc

CD Value
original + 1 month of interest
and so on

except months is across from CD Value.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I know what you're doing wrong, you have a few problems here.
First this formula:

is wrong.

if my deposit is 500 and my annual % yield is 2% then this returns 500.83333333, this is the total i accumulated not the amount yield per month.
the correct formula is:


Second, you don't need to redefine monthlyYield as monthlyYield1, because it doesnt change from month to month, its constant.

Third, you dont need two for loops, you only need one.
declare a new variable to hold to total cd value;
example:


hope this helps
Hunter.
 
Andrew Albers
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks alot for the help it is very much appreciated. i gotta say this site is much more beginner friendlier than others.
 
Piet Souris
Rancher
Pie
Posts: 1213
25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note however that the code above is correct, provided you don't need to work with compound interest, which is very unusual (especially when the number of months is more than 12).

Greetings,
Piet
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic