<br><br><div class="gmail_quote">On Wed, Dec 22, 2010 at 2:04 AM, Stephen Bloch <span dir="ltr"><<a href="mailto:sbloch@adelphi.edu">sbloch@adelphi.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im"><br>
On Dec 21, 2010, at 6:50 AM, Sayth Renshaw wrote:<br>
<br>
</div><div class="im">> Doing the netpay of employee tax = 0.15 and pay = hrs *12. From the beginner tutorial. I see two ways a simple and a hard way but neither work.<br>
><br>
> Hard way<br>
><br>
> (define (hours h)<br>
> (h : number?))<br>
> (define (tax t)<br>
> (= t 0.15))<br>
> (define (payrate p)<br>
> (= p $12.00))<br>
> (define (netpay hours tax payrate)<br>
> (* h p)-(* t(* h p)))<br>
<br>
</div>Something else I forgot to mention in my previous message: you're quite right to want to give names to the tax rate and the hourly pay. The usual way to do this in Beginner Racket would be<br>
(define tax-rate 0.15)<br>
(define pay-rate 12)<br>
Note that these definitions are OUTSIDE the definition of "netpay".<br>
<br>
You can then use these in functions you define. For example, the "inventory" step of this function definition would become<br>
<div class="im"> (define (netpay hours)<br>
; hours a number<br>
</div> ; pay-rate a number ($/hour)<br>
; tax-rate a number<br>
...<br>
)<br>
and then the body could use all three of these variable names.<br>
<br>
Later in the book, you'll learn another way to do it, using "local variables" so the names "tax-rate" and "pay-rate" are visible only INSIDE "netpay":<br>
(define (netpay hours)<br>
(local [(define tax-rate 0.15)<br>
(define pay-rate 12)]<br>
; hours a number<br>
; tax-rate a number<br>
; pay-rate a number ($/hour)<br>
...<br>
))<br>
This version doesn't work in Beginning Student Language, though; you need Intermediate Student Language.<br>
<div><div></div><div class="h5"><br>
<br>
<br>
<br>
Stephen Bloch<br>
<a href="mailto:sbloch@adelphi.edu">sbloch@adelphi.edu</a><br>
<br>
</div></div></blockquote></div><br>Firstly thank you very much for the feedback and ideas its very appreciated.<br><br>I am following the book again and your examples but i am rewriting examples so I am learning it.<br><br>
I came to this as a solution based on feeedback but it is erroring on the word gross as part of my netpay function. Do i need to define the gross function in my netpay function?<br><br> (define tax-rate 0.15)<br> (define pay-rate 12)<br>
(define (gross hours)<br> (* hours pay-rate))<br> <br> (define (netpay gross tax-rate)<br> (gross (- tax-rate)))<br><br>Not quite grabbing something intrinsic, unfortunately Norman this is the start of the book..If I have defined gross function as suggested earlier why can't my netpay function use it?<br>