1 Replies - 818 Views - Last Post: 24 January 2011 - 11:01 PM

#1 good_boy22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-January 11

defining in drracket and solving text problems

Posted 23 January 2011 - 03:27 PM

when i try to write this on drracket, it always says that i have a problem that the names i give are not defined.
this is my version
(define (extra-interest principle-amount-invested interest-rate number-of-years)
  (- profit-compound-interest
     annual-interest))
(define annual-interest
    (* principle-amount-invested (expt (+ 1 interest-rate) number-of-years)))
(define compound-interest
    (* principle-amount-invested (expt (+ 1 (/ interest-rate times-interest-compound))(* times-interest-compound number-of-years)))
    )
(define profit-compound-interest
  (- compound-interest
     principle-amount-invested))



thi is the question itself:
Most people realize that interest compounded monthly is more profitable than interest
accrued annually on an investment. For example, if you have an annual interest rate of 12%
on $1000 investment and you get paid interest once a year, then after one year you would
have $1120. However, if you were paid 1% each month, after the first month you would have
$1010 and you would be earning interest on more money for the second month. After the
second month, you would have $1020.10. After 12 months you would have approximately
$1126.83. This means that by using monthly interest rather than annual interest you
increased the output of your investment by approximately $6.83 over one year.
The formula to calculate the future value of an investment where interest is accrued
annually is: P(1 + r)t, where P is the principle amount invested, r is the interest rate (a
number normally between 0 and 1), and t is the number of years of the investment. A
formula to calculate compound interest is: P(1 + r/n)nt, where P is the principle, r is the
annual interest rate, n is the number of times that interest is compounded each year, and t is
the number of years of the investment.
Write a function called extra-interest that consumes the principle amount invested (a
non‐negative number), the annual interest rate (a non‐negative number), and the number of
years of the investment (a non‐negative integer), and produces the difference between the
profit earned using interest compounded monthly (12 times a year) and interest accrued
annually. For example, (extra-interest 1000 0.12 1) produces
6.825030131969720661201. Note that your function does not need to round off the result to
the nearest penny. However, you may use check-within with a tolerance of 0.00001 for
testing purposes. The built‐in Scheme function expt may be useful.

Edited by macosxnerd101: Added code tags and moved to Functional Programming.

Is This A Good Question/Topic? 0
  • +

Replies To: defining in drracket and solving text problems

#2 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 590
  • View blog
  • Posts: 2,792
  • Joined: 05-January 09

Re: defining in drracket and solving text problems

Posted 24 January 2011 - 11:01 PM

You define an extra-interest function, but you never use it. Also, you're trying to access extra-interest's parameters from an entirely different define. extra-interest is a function, and a function's arguments aren't top-level definitions, thus you can't access them outside of the scope of that function.

This code just doesn't make any sense.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1