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

Username:   Password: 
 RegisterRegister   
 Checking if the result is a natural number
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Diablo117




PostPosted: Tue Jul 07, 2009 8:13 pm   Post subject: Checking if the result is a natural number

What is it you are trying to achieve?
After dividing a number, I want to see if it really IS divisible by finding out if the number outputted was natural, or decimal

What is the problem you are having?
Don't know if turing can do that or not

Please specify what version of Turing you are using
4.0.5
Sponsor
Sponsor
Sponsor
sponsor
syntax_error




PostPosted: Tue Jul 07, 2009 8:32 pm   Post subject: RE:Checking if the result is a natural number

look up, the term mod.

That should be more then enough for you.

And, yes it can.
Diablo117




PostPosted: Wed Jul 08, 2009 1:45 am   Post subject: Re: Checking if the result is a natural number

wow, I feel as if I've been hit over the hit with an unusually large club for me not even thinkin of using mod in that way...lol
saltpro15




PostPosted: Wed Jul 08, 2009 9:48 am   Post subject: RE:Checking if the result is a natural number

Turing:

if num mod 2 = 0
then
...
end if
apomb




PostPosted: Wed Jul 08, 2009 12:17 pm   Post subject: Re: RE:Checking if the result is a natural number

saltpro15 @ Wed Jul 08, 2009 9:48 am wrote:
Turing:

if num mod 2 = 0
then
...
end if


wouldnt that just check if the number is even?
DtY




PostPosted: Wed Jul 08, 2009 12:51 pm   Post subject: Re: RE:Checking if the result is a natural number

apomb @ Wed Jul 08, 2009 12:17 pm wrote:
saltpro15 @ Wed Jul 08, 2009 9:48 am wrote:
Turing:

if num mod 2 = 0
then
...
end if


wouldnt that just check if the number is even?

num mod 2 would test if it's divisible by two. You'd replace two with whatever number you need to check if you can divide by.
Insectoid




PostPosted: Wed Jul 08, 2009 1:41 pm   Post subject: RE:Checking if the result is a natural number

Another way,,

code:

if num div X = num/X then
   ...
end if
DtY




PostPosted: Wed Jul 08, 2009 9:06 pm   Post subject: Re: RE:Checking if the result is a natural number

insectoid @ Wed Jul 08, 2009 1:41 pm wrote:
Another way,,

code:

if num div X = num/X then
   ...
end if

Although that method is slower and makes less sense..
Sponsor
Sponsor
Sponsor
sponsor
saltpro15




PostPosted: Wed Jul 08, 2009 9:39 pm   Post subject: RE:Checking if the result is a natural number

Embarassed thanks for correcting that guys
Zren




PostPosted: Wed Jul 08, 2009 11:03 pm   Post subject: Re: Checking if the result is a natural number

I like my method.

Turing:
if num = floor(num) then
put "Integer"
else
put "Real Number"
end if
syntax_error




PostPosted: Wed Jul 08, 2009 11:35 pm   Post subject: Re: Checking if the result is a natural number

Zren @ Wed Jul 08, 2009 11:03 pm wrote:
I like my method.

Turing:
if num = floor(num) then
put "Integer"
else
put "Real Number"
end if


Hmm, seems like the smallest amount of code to me, nice.
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  [ 11 Posts ]
Jump to:   


Style:  
Search: