The following code is to find out how many different ways can we make change given half-dollars, quarters, dimes, nickels, and pennies? Can someone explain how this procedure executes? How the cc function recurses? I tried tracing this procedure but I am not sure how the cc function can recurse when it subtracts the amount from the same denomination each time the function is called wouldn't the amount eventually reach 0? Also, I don't understand why are there 2 different recursive calls to cc? Any help would be appreciated.
(define (count-change amount)
(cc amount 5))
(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
(first-denomination kinds-of-coins))
kinds-of-coins)))))
(define (first-denomination kinds-of-coins)
(cond ((= kinds-of-coins 1) 1)
((= kinds-of-coins 2) 5)
((= kinds-of-coins 3) 10)
((= kinds-of-coins 4) 25)
((= kinds-of-coins 5) 50)))
(count-change 10)