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

Username:   Password: 
 RegisterRegister   
 variable type change
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mat




PostPosted: Sun Apr 10, 2005 6:03 pm   Post subject: variable type change

how do i change variable types?

ie real to an int


thanks
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Sun Apr 10, 2005 6:09 pm   Post subject: (No subject)

Easy. Use a round command.
code:
var r : real := 4.5678
var i : int := round (r)
put i

But if you just round r, it still cannot be used as an integer.
code:
r := round (r)
for q : 1 .. r
end for


strint / intstr = changing strings and integers
realstr / strreal = changing string and reals.
There are also more options for realstr, but that one's basic.
Look up frealstr and erealstr in F10 help.
mat




PostPosted: Sun Apr 10, 2005 6:21 pm   Post subject: (No subject)

i think i needed to give more detail...

How would i add a rounded real number to an int variable that already exists?

basicly, could i switch the real to an int (not rounding) so i could add it to other ints?

is there a command for real to int like there is for string to int (strint)
?erealint, or something? that does not work.
thanks again,
jamonathin




PostPosted: Sun Apr 10, 2005 6:41 pm   Post subject: (No subject)

You do a '+' sign?

Works.
code:

var q : real := 5
var p : int := 1
put p + q

%or

var q : real := 5.4
var p : int := 1
put p + round (q)


Doesn't Work.
code:
var q : real := 5.4
var p : int := 1
put p + q


As long as the real number is whole, it can be added to an integer. There's no way to actually chane the real to an integer, but you can round the real number and make a new integer variable equal to that real number.
Drakain Zeil




PostPosted: Sun Apr 10, 2005 6:53 pm   Post subject: (No subject)

intreal
realint
strint
intstr

and I think there's some others.
jamonathin




PostPosted: Sun Apr 10, 2005 7:34 pm   Post subject: (No subject)

Drakain Zeil wrote:
intreal
realint
strint
intstr

and I think there's some others.


intreal? realint? lol... it's called
code:
real_var:=int_var
and
int_var:=round(real_var)

those don't exist, mainly because there's no point Confused
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  [ 6 Posts ]
Jump to:   


Style:  
Search: