
-----------------------------------
nmr123321
Tue Oct 18, 2005 7:59 pm

Help with Calculating Compound interests in loop
-----------------------------------
I new this is so newbish problem but i am only learning turing for like 20 days
Please tell me what am i doing wrong
Question
Calculate Compound interest in 10 years for eack year with the initial amount of 1000 and rate of 6%
%Calculate Compound interest in 10 years for eack year with the initial amount of 1000 and rate of 6%
var balance:int:=1000
var year:int:=0
var interest:int:=0
const rate:=0.06
loop
put balance,"    ",year,"     ",interest
interest:=balance*rate
balance:=balance+interest
year:=year+1
end loop

-----------------------------------
beard0
Tue Oct 18, 2005 8:36 pm


-----------------------------------
Balance and interest you have as integers, they need to be of type real, because when you multiply by 0.06, you don't get an integer answer.

:idea: When you're looking for help after getting an error message, please post the error message.

-----------------------------------
lyam_kaskade
Tue Oct 18, 2005 8:38 pm


-----------------------------------
Hmm... the loop doesn't have an exit condition.
Try


exit when year = 10


before the end of the loop.
And then another output statement after the loop, so it shows the final result.

Also, instead of 
year:= year +1


You can put
year += 1


Not that it's a big deal, just makes code more readable.

-----------------------------------
nmr123321
Tue Oct 18, 2005 8:46 pm


-----------------------------------
thanks a lot guys+bits

-----------------------------------
nmr123321
Tue Oct 18, 2005 8:49 pm


-----------------------------------
i'm trying to donate bits but i am getting the following message

Could not update points log

DEBUG MODE

SQL Error : 1136 Column count doesn't match value count at row 1

UPDATE v3_users SET user_points = user_points + 5 WHERE user_id = 1516

Line : 179
File : /home/compsci/public_html/v2/pointscp.php

-----------------------------------
beard0
Tue Oct 18, 2005 9:13 pm


-----------------------------------
Don't worry about it.  The bit donation system has been down for a while now.

-----------------------------------
MysticVegeta
Wed Oct 19, 2005 2:37 pm


-----------------------------------
Why not use the formula? 

CI = P(1+r)^n

In turing it would be

var CI : real := 1000 * ( (1 + .06) ** 10)

No need for a loop!

-----------------------------------
beard0
Wed Oct 19, 2005 2:44 pm


-----------------------------------
Why not use the formula? 
CI = P(1+r)^n
In turing it would be
var CI : real := 1000 * ( (1 + .06) ** 10)
No need for a loop!
Because he's taking a computer science course, not a math course
Because he needs to print out the value for each year which means that the computer has less calculations to do using his method

-----------------------------------
MysticVegeta
Wed Oct 19, 2005 2:46 pm


-----------------------------------
oh sorry I misunderstood the point.

-----------------------------------
beard0
Wed Oct 19, 2005 2:50 pm


-----------------------------------
oh sorry I misunderstood the point.
You didn't need to appologise.  We forgive you your ignorance.  :lol:  I guess my reply was a little more hard-edged than I meant it to be...
