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

Username:   Password: 
 RegisterRegister   
 Math with decimals
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
aldreneo




PostPosted: Mon Jun 19, 2006 2:25 pm   Post subject: Math with decimals

code:

var number1:int
get numberone
numberone * 2
print numberone


How do I make it so that numberone has a decimal in it and still be able to do math with it?

Example output I would like:
code:

2.3
4.6
Sponsor
Sponsor
Sponsor
sponsor
r.3volved




PostPosted: Mon Jun 19, 2006 2:45 pm   Post subject: (No subject)

Data type of integer uses whole numbers with no decimal places.
so your datatype should be (been a long time since I used hideous turing) Double, Float, Real or Decimal...whatever turing uses
Delos




PostPosted: Mon Jun 19, 2006 2:46 pm   Post subject: (No subject)

You could simply use real variables instead:

code:

var real_number : real


Also, you don't print output in Turing, you put it Wink.
aldreneo




PostPosted: Mon Jun 19, 2006 3:05 pm   Post subject: (No subject)

Thanks

And allmost every other language uses print why does turing use put?
Delos




PostPosted: Mon Jun 19, 2006 3:35 pm   Post subject: (No subject)

Why does Ruby use 'puts'? I'm not sure there's a satisfactory answer to that. If it makes you feel better, you could add this to an Output module:

code:

procedure print (text : string)
   put text
end print
% And add others for ints, reals, etc, since Turing can't handle function overloading.
s3arkay




PostPosted: Mon Jun 19, 2006 3:43 pm   Post subject: (No subject)

code:

var num : real
get real
put real :0:2


That would print the number with 2 decimals even if it didnt have any,

Example : 2.00
aldreneo




PostPosted: Tue Jun 20, 2006 9:33 am   Post subject: (No subject)

but, that would be without rounding
s3arkay wrote:
code:

var num : real
get real
put real :0:2


That would print the number with 2 decimals even if it didnt have any,

Example : 2.00
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: