Computer Science Canada

Math with decimals

Author:  aldreneo [ 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

Author:  r.3volved [ Mon Jun 19, 2006 2:45 pm ]
Post 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

Author:  Delos [ Mon Jun 19, 2006 2:46 pm ]
Post 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.

Author:  aldreneo [ Mon Jun 19, 2006 3:05 pm ]
Post subject: 

Thanks

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

Author:  Delos [ Mon Jun 19, 2006 3:35 pm ]
Post 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.

Author:  s3arkay [ Mon Jun 19, 2006 3:43 pm ]
Post 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

Author:  aldreneo [ Tue Jun 20, 2006 9:33 am ]
Post 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


: