and having talked about binary code in physics, i wanted to see if i could create a program in scheme that converted from decimal to binary, (don't care about the other way around yet.)
now i know there's probably a pre-made definition for this in Dr. scheme somewhere, but i want to make it myself for the sake of self accomplishment (which is why i'm asking for help o.o)
here is what my code looks like so far:
(define (dec->bin x)
(cond[(equal? 1 x) (print 1)]
[(equal? 0 x) (print 0)]
(else (print (remainder x 2))) ;<-- either problem is here
)
(cond[(equal? (- x (remainder x 2)) 0) (printf " ")]
[(> (- x (remainder x 2)) 0) (print (dec->bin (/ (- x (remainder x 2)) 2)))] ; <-- or here
))
and my problem: it keeps returning #<void> in one of the parts where there is a "print(" followed by " the value x" (shown in code)
edit: i am aware that the code is displayed backwards, but il fix that later, for now i want to get rid of those #<void> 's :P
i don't know what i'm doing wrong :S, plz help, thanks in advance
Edited by Soupdude, 09 November 2009 - 04:00 PM.
fixing it


Sign In
Create Account

Back to top









