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

Username:   Password: 
 RegisterRegister   
 Whole Number Finding?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mattpk




PostPosted: Mon Sep 21, 2009 7:52 pm   Post subject: Whole Number Finding?

How would i check if a number is a whole number through turing? I want to make a program that finds factors for you
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Sep 21, 2009 8:14 pm   Post subject: RE:Whole Number Finding?

Strictly speaking, you can check for
code:

num == intreal(round(num))


But really, you are looking for the modulo operator.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
OneOffDriveByPoster




PostPosted: Mon Sep 21, 2009 8:15 pm   Post subject: Re: Whole Number Finding?

mattpk @ Mon Sep 21, 2009 7:52 pm wrote:
How would i check if a number is a whole number through turing? I want to make a program that finds factors for you
It looks like you are trying trial division. Turing provides "rem" which the remainder.
mattpk




PostPosted: Mon Sep 21, 2009 8:35 pm   Post subject: RE:Whole Number Finding?

i didnt one hundred percent understand you guys, but i was able to find out that i could do



Quote:
loop
if round(num / count) = num / count
then factor := count
put factor
end if

count -= 1
exit when count = 0
end loop
Tony




PostPosted: Mon Sep 21, 2009 8:45 pm   Post subject: RE:Whole Number Finding?

code:

if num mod count = 0 then
   put count
end if
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Kharybdis




PostPosted: Tue Sep 22, 2009 2:16 pm   Post subject: RE:Whole Number Finding?

There's also a simple error check that you can do.

Turing:


var num : string
get num
if strintok (num) then
    put "Whole number."
else
    put "Real number/Complex Number/Word"
end if

andrew.




PostPosted: Tue Sep 22, 2009 4:18 pm   Post subject: RE:Whole Number Finding?

You can do this multiple ways. One way is to round it and see if it is different. If it is, then it wasn't an integer. Another way is to do what Kharybdis said and convert the number to a string (or get it as a string) and then see if it's okay for it to be an integer (strintok). If it is, then it is an integer, otherwise it's something else.
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: