
-----------------------------------
JR
Wed Apr 13, 2005 8:08 am

if statement question
-----------------------------------
Hey i got a binary convertion program and i was wondering how do i check if the number that was entered by the user only has 1's and 0's ?

-----------------------------------
Tony
Wed Apr 13, 2005 8:17 am


-----------------------------------
convert to string, then loop though characters.

var text : string := intstr (1001200)
for i : 1 .. length (text)
    if text (i) = "1" or text (i) = "0" then
        put text (i)
    else
        put "foo"
    end if
end for

now obviously instead of saying "foo", you'll simply quit the loop and show an error.

-----------------------------------
jamonathin
Wed Apr 13, 2005 8:20 am


-----------------------------------
use a for loop to check every character in the string/int variable.  And in that for loop use an if statement that says if the character at the for loop number is equal to 1 or 0 then do whatever.
p.s. run the for loop for the legnth of the binary.  if your binary is int, use length(intstr(binary))
EDIT: man i type slow. .
