Note that there are some explanatory texts on larger screens.

plurals
  1. PORacket basic question
    text
    copied!<p>I'm beginning Racket, and (being a rookie) I'm having some trouble finding out what's exactly wrong with my code. At first, I tried implementing the thing as a single function, and it worked fine:</p> <pre><code>; Finds surface area of pipe ; outside surface area (2pir+thickness)*length ; inside SA 2pirad*length ; 2 (area of outer circle - area of inner circle) ; add all together (define (area-pipe inner_radius height thickness) (+ (* 2 pi inner_radius height) (* 2 pi height (+ inner_radius thickness)) (- (* 2 pi (sqr (+ inner_radius thickness))) (* 2 pi (sqr inner_radius))))) </code></pre> <p>And (since I'm following the tutorials provided <a href="http://www.cs.brown.edu/courses/csci1730/2010/Assignments/support/tutorial1.pdf" rel="nofollow">here</a>), I set out to implement this as a combination of functions, to which I ended up with the following:</p> <pre><code>; functional implementation (define (area-circle radius) (* 2 pi (sqr radius))) (define (area-cylinder radius height) (* 2 pi (sqr radius) height)) ;actual function--why doesn't this quite work as planned? (define (area-pipe1 inner_radius height thickness) (+ (area-cylinder inner_radius height) (area-cylinder (+ inner_radius thickness) height) (- (area-circle (+ inner_radius thickness)) (area-circle inner_radius)))) </code></pre> <p>So, I'm <em>guessing</em> that there's a problem with my definitions. However, I'd appreciate some hints and nudges towards why I'm not receiving the right answers. As tests, the site provides the following code:</p> <pre><code>(test (area-pipe1 0.5 0 0.5) 4.71) (test (area-pipe1 0 2 1) 18.85) (test (area-pipe1 1 2 1) 56.54) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload