tags:

views:

59

answers:

3

Hi (geek) folks,

I'm fiddling another time with a (should be easy) task.

compound interest... (formula is known) Scheme... (For one single years everything works flawlessy)

Problem: Accumulator needed... My program has to be able to remember the result of the former calculation and put it as a blueprint for the next one following.

Here comes my question: How to setup accu-procedures without lists....? Or am I deadly wrong for now, and I must use them?

Somehow I'll have to call the recursive procedure again and again...

Many thanks in advance, sincerely, Andreas_P

Andreas_P

A: 

Do you mean something like:

(define (fv n pv r)
  (if (= n 0)
      pv
      (fv (- n 1) (* pv (+ 1 r)) r)))

where the value of pv is replaced by the value at the end of the period, and the number of periods is reduced by one each recursion.

SICP has good coverage of how to structure recursion --- it's worth a read.

spong
+1  A: 

Reading your question makes me a bit dizzy. I have a bunch of answers for you, but I get the sense that you're not quite sure what your question is.

My real advice for you is a generous helping of How To Design Programs. Specifically, you need to start at step one, and decide what your program takes in and produces, and write a one-line description of how the inputs are mapped to the outputs.

As always, apologies for any offense given.

John Clements
A: 
awhateverp