Calculating Compound Interest

Blitz3D Forums/Blitz3D Programming/Calculating Compound Interest

wizzlefish(Posted 2005) [#1]
I'm trying to write a function for calculating compound interest.

Here's my code:
Graphics 800,600


Print CalcCompoundInterest(100,0,15)
WaitKey
End 


;Calculates Compound Interest
;principal, rate, time
Function CalcCompoundInterest(p,r#,t)
	
	r# = r#	
	For a = 0 To t
		i = p*r#
		p = p + i
	Next

End Function


That is supposed to return "100," because with 0 interest for any amount of years, you would stay at the principal. But instead, it just returns "0."

What do I need to change?


wizzlefish(Posted 2005) [#2]
Nevermind. Figured it out.


GfK(Posted 2005) [#3]
You aren't returning a value from your function.


wizzlefish(Posted 2005) [#4]
Yes. Stupid me!

I don't know much about string functions. I thought it "automatcially" returned it or something stupid like that.


Rook Zimbabwe(Posted 2005) [#5]
So this is wht you are looking for?
Graphics 800,600
Global i
Global t
Global r#
Global p
Global p2

p=100000
r#=.06 ; note 6 percent for a house
t=15

CalcCompoundInterest(p,r#,t)
mos=t*12
month=p2/mos
Text 0,0,"Principal: "+ p
Text 0,15,"RATE: "+ r# + " %"
Text 0,30,"TERM (YRS): "+ t
Text 0,45,"Interest: "+i
Text 0,60,"P + Int: "+p2
Text 0,85,"Monthly Pay: "+month
WaitKey
End 


;Calculates Compound Interest
;principal, rate, time
Function CalcCompoundInterest(p,r#,t)
	
	r# = r#	
	For a = 0 To t
		i = p*r#
		p2 = p + i
	Next
Return i And p2

End Function

Interesting... my wifes an accountant she does this in a different way... :)
RZ


Who was John Galt?(Posted 2005) [#6]
There's a formula to calculate it without multiple calculations - maybe that's what your wife's using.


Rook Zimbabwe(Posted 2005) [#7]
Probably... I myself only know Prt... so I know VERY little!


wizzlefish(Posted 2005) [#8]
Prt is for simple interest. I just studied this today - I'll forget it by tomorrow. :P

And there is a formula for it:
P(1+r)^t

I think that's the one for compound interest.

P*r*t is for simple interest.


Rook Zimbabwe(Posted 2005) [#9]
Hmmm can this be right?
Looks too simple...