Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with Calculating Compound interests in loop
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nmr123321




PostPosted: Tue Oct 18, 2005 7:59 pm   Post subject: 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%
code:
%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
Sponsor
Sponsor
Sponsor
sponsor
beard0




PostPosted: Tue Oct 18, 2005 8:36 pm   Post subject: (No subject)

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




PostPosted: Tue Oct 18, 2005 8:38 pm   Post subject: (No subject)

Hmm... the loop doesn't have an exit condition.
Try

code:

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
code:

year:= year +1


You can put
code:

year += 1


Not that it's a big deal, just makes code more readable.
nmr123321




PostPosted: Tue Oct 18, 2005 8:46 pm   Post subject: (No subject)

thanks a lot guys+bits
nmr123321




PostPosted: Tue Oct 18, 2005 8:49 pm   Post subject: (No subject)

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




PostPosted: Tue Oct 18, 2005 9:13 pm   Post subject: (No subject)

Don't worry about it. The bit donation system has been down for a while now.
MysticVegeta




PostPosted: Wed Oct 19, 2005 2:37 pm   Post subject: (No subject)

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




PostPosted: Wed Oct 19, 2005 2:44 pm   Post subject: (No subject)

MysticVegeta wrote:
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!

  1. Because he's taking a computer science course, not a math course
  2. Because he needs to print out the value for each year which means that the computer has less calculations to do using his method
Sponsor
Sponsor
Sponsor
sponsor
MysticVegeta




PostPosted: Wed Oct 19, 2005 2:46 pm   Post subject: (No subject)

oh sorry I misunderstood the point.
beard0




PostPosted: Wed Oct 19, 2005 2:50 pm   Post subject: (No subject)

MysticVegeta wrote:
oh sorry I misunderstood the point.

You didn't need to appologise. We forgive you your ignorance. Laughing I guess my reply was a little more hard-edged than I meant it to be...
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: