I was reading the SICP and encountered with a problem, in chapter 1 there is an example named counting change, I need to write a program in scheme to calculate the possible number of ways to make a change of any given number given half-dollars, quarters, dimes, nickles and pennies. the book shows a substitution model of program and I tried to change it to a nesting one but failed, could anyone give me a favor?
(define (count_change total_amount)
(define (denomination kinds_of_coins)
(cond ((= kinds_of_coins 5) 50)
((= kinds_of_coins 4) 25)
((= kinds_of_coins 3) 10)
((= kinds_of_coins 2) 5)
((= kinds_of_coins 1) 1)))
(define (cc amount kinds_of_coins)
(cond (= amount 0) 1)
((or (< amount 0) (= kinds_of_coins 0)) 0)
(else (+ (cc amount (- kinds_of_coins 1))
(cc (- amount (denomination kinds_of_coins)) kinds_of_coins))))
(cc total_amount 5))
the execution result is as follows:
;Ill-formed clause: 1