a more realistic problem
calculating compound interest
- procedure to calculate compound interest
(define (compound principal rate term)
(define (citer year gross)
(if (= term year) gross (citer (inc year) (+ gross (* gross rate)))))
(citer 0 principal))
- sample evaluations
(compound 1000 0.05 20) ; evals to 2653
(compound 1000 0.05 40) ; evals to 7040 – so invest early!
(compound 1000 0.10 40) ; evals to 45259 – so get good rate!