
-----------------------------------
mattpk
Mon Sep 21, 2009 7:52 pm

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

-----------------------------------
Tony
Mon Sep 21, 2009 8:14 pm

RE:Whole Number Finding?
-----------------------------------
Strictly speaking, you can check for
modulo operator.

-----------------------------------
OneOffDriveByPoster
Mon Sep 21, 2009 8:15 pm

Re: 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 youIt looks like you are trying trial division.  Turing provides "rem" which the remainder.

-----------------------------------
mattpk
Mon Sep 21, 2009 8:35 pm

RE:Whole Number Finding?
-----------------------------------
i didnt one hundred percent understand you guys, but i was able to find out that i could do 



loop
if round(num / count) = num / count
then factor := count
put factor
end if

count -= 1
exit when count = 0
end loop

-----------------------------------
Tony
Mon Sep 21, 2009 8:45 pm

RE:Whole Number Finding?
-----------------------------------
[code]
if num mod count = 0 then
   put count
end if
[/code]

-----------------------------------
Kharybdis
Tue Sep 22, 2009 2:16 pm

RE:Whole Number Finding?
-----------------------------------
There's also a simple error check that you can do.



var num : string
get num
if strintok (num) then
    put "Whole number."
else
    put "Real number/Complex Number/Word"
end if

 

-----------------------------------
andrew.
Tue Sep 22, 2009 4:18 pm

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.
