Calculating Compound Interest

Blitz3D Forums/Blitz3D Programming/Calculating Compound Interest

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?

Nevermind. Figured it out.

You aren't returning a value from your function.

Yes. Stupid me!

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

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

There's a formula to calculate it without multiple calculations - maybe that's what your wife's using.

Probably... I myself only know Prt... so I know VERY little!

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.

Hmmm can this be right?
Graphics 800,600
Global i
Global t
Global r#
Global p
Global p2
Global golly

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,"Compound Interest"
Text 0,15,"Principal: "+ p
Text 0,30,"RATE: "+ r# + " %"
Text 0,45,"TERM (YRS): "+ t
Text 0,60,"Interest: "+i
Text 0,75,"P + Int: "+p2
Text 0,100,"Monthly Pay: "+month
CalcSimpleInterest(p,r#,t)
Text 0,130,"Simple Interest"
gol=golly/mos
Text 0,145,"Simply by the month: "+gol
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

Function CalcSimpleInterest(p,r#,t)
golly=p*r*t
Return golly

End Function
Looks too simple...