Hey guys im learning how to use DrRacket. I have one problem giving me trouble. Im not sure how to set up a list entered to return a min.
Im trying to create a procedure that finds the min number from the keyboard until 0 is read, and that's adds them up. Note that 0 is included in the computation.
ANY help would be great.
Thanks
DrRacket Problem
Page 1 of 12 Replies - 5964 Views - Last Post: 08 November 2012 - 03:28 PM
Replies To: DrRacket Problem
#2
Re: DrRacket Problem
Posted 07 November 2012 - 10:34 AM
(define (minimum-list x) (cond [(empty? (rest x)) (first x)] [else (min (first x) (minimum-list (rest x)))])) (display (minimum-list (read)))
I have this so far, but I need to be able to enter numbers without having to use paranthesis... With this code, it works, but I need to write it with paranthesis for ex. (1 3 -3).. I need it 1 3 -3
Any help would be awesome
#3
Re: DrRacket Problem
Posted 08 November 2012 - 03:28 PM
read reads a Racket value, so the input has to be entered using Racket syntax. Since you don't want that, you should use read-line which reads a line of input (without caring how it's formatted) and returns it as a string. You can then use string-split to turn that string into a list by splitting on white space.
This post has been edited by sepp2k: 09 November 2012 - 08:19 AM
Page 1 of 1

New Topic/Question
Reply


MultiQuote


|