Working through HTDP and I got to this example(below) I created a working function but I reused a function, is there a better way to assign a variable in another function so, for refernce this was the question.<br><br><b>Exercise 4.4.2.</b>
Develop the function <code class="scheme"><span class="variable">tax</span></code>, which consumes the gross pay and produces
the amount of tax owed. For a gross pay of $240 or less, the tax is 0%; for
over $240 and $480 or less, the tax rate is 15%; and for any pay over
$480, the tax rate is 28%.<br><br>My Working solution<br><br>;;; Given a gross wage determine the tax that applies taxed in bands<br>;;; number -> number<br>;;; less than 240, greater than 240 < 480, greater than 480<br>
(define (tax_pay pay)<br> (cond<br> [(<= pay 240) 0]<br> [(<= pay 480) (* pay 0.15)]<br> [(> pay 480) (* pay 0.28)]))<br><br>(define (pay hours)<br> (* 12 hours))<br>;;; Calculate netpay (pay - tax)<br>
;;; Pay rate 12 and user input hours<br>;;; (pay (payrate * hours)) - (pay -(tax (pay * tax percent)) <br>(define (netpay hours)<br> (- (pay hours)(tax_pay (pay hours))))<br><br>Proposed solution - assign a variable to the pay calculation and reuse it, however it thinks I am redefining the function tax_pay. In embryo this is a better way to crack the egg isn't it?<br>
<br>(define (netpay2 hours)<br> (h (pay hours)<br> (- h (tax_pay h))))<br>