Op 22-2-2012 9:58, Roelof Wobben schreef:
> Thanks,
>> I have now a answer to my question.
> I will debug my programm with check-expect and wil take a look at the
> second edition.
>> Roelof
>>>> Op 21-2-2012 22:40, Stephen Bloch schreef:
>>>> On Feb 21, 2012, at 3:18 PM, Roelof Wobben wrote:
>>>>> Op 21-2-2012 20:51, Stephen Bloch schreef:
>>>> On Feb 21, 2012, at 2:43 PM, Roelof Wobben wrote:
>>>>>>>>> But now I get this error message :
>>>>> unsaved editor>:27:23: function call: expected a function after the open parenthesis, but found a part in: (tarief1 amount)
>>>>>>>>>> When I do (tarief 1 amount) instead of ((tarief amount))
>>>> Yes, that's where the syntax error is. So you've fixed that.
>>>>>> I fixed that? I always thought that if I use another function that
>>> I must be into ().
>>> So In my opinion one () for the then part and one () for the
>>> function call.
>>>> No, there is no pair of parentheses for the "then" part, only one for
>> the function call.
>>>> (cond [question answer]
>> [question answer]
>> ...
>> [question answer])
>> where each question and each answer is an expression (usually a
>> function call).
>>>>>> 1) Have you written a complete set of test cases, with right answers, using "check-expect"? Since there are four categories of input for this problem, you need at least four test cases, and you should probably have three more for the boundaries, a total of seven test cases.
>>>>>> Nope, check-expect is not explained on chapter section 3 of the book
>>> how to design programms. So I did not use that function. I can make
>>> test-cases but then in this form
>>>>>> (= (/tarief 495/) 1,2375)
>>>> That should work too, although it's not as convenient. Make sure you
>> put a bunch of those test cases in the Definitions pane, after the
>> definition:
>>>> (define (tarief blah blah)
>> blah blah blah
>> )
>>>> (= (tarief 495) 1,2375)
>> (= (tarief 0) 0)
>> (= (tarief 100) whatever)
>> ...
>>>> That will also solve the next problem:
>>>>> 3) Have you used the Stepper to watch what your program is doing?
>>>>>> Yes, when I do (payback 2600) on the prompt and press Step I only
>>> see a message All definitions have been sucessfully evaluated and
>>> not other outcome so that did not help me any further.
>>>> The Stepper only works on expressions in the Definitions pane, not
>> the Interactions pane. If you put your test cases in the Definitions
>> pane as described above, the Stepper will help you find where things
>> are going wrong.
>>>> BTW, check-expect is not discussed in _How to Design Programs_
>> because it hadn't been invented yet when the book was written. It's
>> quite easy to use, though: replace the = sign in the above tests with
>> check-expect, and when you hit "Run" you'll get a report of which of
>> your test cases worked, the expected answer and the actual answer.
>>>> You might consider working through the Second Edition of _How to
>> Design Programs_ instead; see
>>http://www.ccs.neu.edu/home/matthias/HtDP2e/ .
>>>>>>>> Stephen Bloch
>>sbloch at adelphi.edu <mailto:sbloch at adelphi.edu>
>>>
I found a working solution but I wonder if there is a better way to
achieve the answer in the Beginning Student modus.
The solution I found is this one:
(define (tarief4 amount)
(*(- amount 2500)0.01))
(define (tarief3 amount)
(cond
[ ( < amount 2500)(* (- amount 1500)0.0075)]
[ else ( * .0075 1000)]))
(define (tarief2 amount)
(cond
[ ( < amount 1500)(* ( - 1000 amount) .0050) ]
[ else ( * 1000 0.0050)]))
(define (tarief1 amount)
(cond
[ (< amount 500) (* 0.0025 amount)]
[ else (* 0.0025 500)]
))
(define (payback amount)
(cond
[ (<= amount 500) (tarief1 amount)]
[ (and ( <= amount 1500) (> amount 500)) (+ (tarief1
amount)(tarief2 amount))]
[ (and ( <= amount 2500) (> amount 1500)) (+ (tarief3 amount)
(tarief2 amount) (tarief1 amount))]
[ else (+ (tarief4 amount)(tarief3 amount)(tarief2 amount)(tarief1
amount))]
)
)
Roelof Wobben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120222/04c6bdce/attachment-0001.html>