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

Username:   Password: 
 RegisterRegister   
 Calculating interest / Help with functions
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Skilgannon




PostPosted: Sun Feb 05, 2006 2:36 pm   Post subject: Calculating interest / Help with functions

I don't quite understand how functions work, and that's probably why this isn't working so well.
Basically, you input the original amount of money, the interest rate and the number of years , and it's compounded yearly.
For some odd reason, it only outputs the first number following "result"
Can someone help me out ?

code:

function invest (p, i, n : int) : int
    result p*(1 + i div 100)**n
end invest

var p1, i1, n1 : int := 0

put "Enter amount of money invested"
get p1
put "Enter interest rate, in percentage"
get i1
put "Enter number of years"
get n1

put invest ( p1, i1, n1)
Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: Sun Feb 05, 2006 2:58 pm   Post subject: (No subject)

I don't know why it would be outputing "result" but I do know that money is not an integer value. You should be using floating point varaibles instead of integers.
Skilgannon




PostPosted: Sun Feb 05, 2006 4:22 pm   Post subject: (No subject)

Thanks, I figured it out.
md




PostPosted: Sun Feb 05, 2006 4:22 pm   Post subject: (No subject)

I'm not actually a turing user, so I don't know exactly what the type would be, but try "float", "double" or "real". Basically it's a variable that can keep track of decimal numbers.
Delos




PostPosted: Sun Feb 05, 2006 4:58 pm   Post subject: (No subject)

Cornflake wrote:
I'm not actually a turing user, so I don't know exactly what the type would be, but try "float", "double" or "real". Basically it's a variable that can keep track of decimal numbers.


Oh I wish Turing had floats and doubles...would be so much more memory effcient! I believe it does have some other random things with regards to natural numbers...
md




PostPosted: Sun Feb 05, 2006 5:18 pm   Post subject: (No subject)

Turing doesn't support floats or doubles?!

/me shakes his head and walks away
Martin




PostPosted: Sun Feb 05, 2006 9:24 pm   Post subject: (No subject)

Turing calls this type real.

var n : real
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  [ 7 Posts ]
Jump to:   


Style:  
Search: