
-----------------------------------
foo fighter
Thu Nov 24, 2005 5:44 pm

using mod
-----------------------------------
Ok here's what i want my program to do:

I want the user to input a number. Then its divided by 2 continuosly until its at zero and for each time it divides if theres a demainder i want it to output a 1 and if no remaider then output a 0.

my friend said i should use mod, but i cant figure it out :(

-----------------------------------
MysticVegeta
Thu Nov 24, 2005 5:50 pm


-----------------------------------
remainder is the mod function. 
for example: 

put 4 mod 2. 
Output will be 0

Because 4/2 = 2. Remainder = 0

-----------------------------------
foo fighter
Thu Nov 24, 2005 6:24 pm


-----------------------------------
ummm... okay, but its not rounding numbers with remainders of 1, it just puts them as 0.5

-----------------------------------
person
Thu Nov 24, 2005 6:56 pm


-----------------------------------
x:= x div 2
y:= x mod 2
put x,y[/quote]

-----------------------------------
[Gandalf]
Fri Nov 25, 2005 4:38 pm


-----------------------------------
Yes, as person's example shows, you must use the div command for the mod (remainder) to be accurate.

-----------------------------------
Dan
Fri Nov 25, 2005 5:16 pm


-----------------------------------
it should be noted that such a progame whould never aucatly hit 0 unless sigficant rounding was used.....

-----------------------------------
person
Fri Nov 25, 2005 6:50 pm


-----------------------------------
put 1 div 2

outputs

0

-----------------------------------
Dan
Fri Nov 25, 2005 9:58 pm


-----------------------------------
put 1 div 2

outputs

0

Thats b/c the div comand is not the same as dividing 2 numbers. It dvides them and then cuts of the decmans (ether by round or truncating them, i whold have to check). 

Since he side divides and not divides and truncates........

Tho i blive that at some point turing whould start round even the number divide using the noraml divsion comand. But a exit condtion based soly on that whould not be good progaming.
