Updated the compound interest script
This commit is contained in:
parent
946af24514
commit
c20bb682f2
|
@ -44,6 +44,9 @@
|
||||||
(assert= 81450 (compound-interest 100000 -5 4))
|
(assert= 81450 (compound-interest 100000 -5 4))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(defun negative-number-of-years ()
|
||||||
|
(assert= 100000 (compound-interest 100000 5 -4))
|
||||||
|
)
|
||||||
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
(defun decrement (n) (- n 1))
|
(defun decrement (n) (- n 1))
|
||||||
|
|
||||||
(defun percent (n percent)
|
(defun percent (n percentage)
|
||||||
(if (> percent 0)
|
(if (> percentage 0)
|
||||||
(/ (+ (* n percent) 50) 100)
|
(/ (+ (* n percentage) 50) 100)
|
||||||
(/ (- (* n percent) 50) 100)
|
(/ (- (* n percentage) 50) 100)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun compound-interest (principal rate years)
|
(defun compound-interest (principal interest-rate years)
|
||||||
(if (= years 0)
|
(if (< years 1)
|
||||||
principal
|
principal
|
||||||
(compound-interest
|
(compound-interest
|
||||||
(+ principal (percent principal rate))
|
(+ principal (percent principal interest-rate))
|
||||||
rate
|
interest-rate
|
||||||
(decrement years)
|
(decrement years)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue