SPEND YOUR MONEY

This program assumes wages are earned and learned. See previous program on calculating wages and taxes.

DATA ANALYSIS
;;cost: number -> number
;;compute cost with a discount of 10% on first $100, 15% on next 400,
;; 25% on next 500, 50% on any amount spent over 1000.
(define (cost $)
EXAMPLES
(cost 50) = 45 (cost 100) = 90 (cost 200) = 175 (cost 500) = 430
(cost 600) = 500 (cost 1000) = 800 (cost 2000) = (+ 800 500) = 1300
BODY
Template ? Conditional Expressions ? Answers
(cond
   [         ]
   [         ]
   [         ] 
   [         ])
  1. (<= $ 100)
  2. (and (> $ 100) (<= $ 500))
  3. (and (> $ 500) (<= $ 1000))
  4. (> $ 1000)

  1. (discount 10 $)
  2. (+ (discount 10 100)
       (discount 15 (- $ 100)))
  3. (+ (discount 10 100)
       (discount 15 400)
       (discount 25 (- $ 500)))
    
  4. (+ (discount 10 100)
       (discount 15 400)
       (discount 25 500)
       (discount 50 (- $ 1000)))
    
Interaction Window
Welcome to DrScheme, 
version 100. Language: Beginner.
45 = 45 90 = 90 175 = 175 430 = 430 505 = 500 805 = 800 1305 = 1300 = 1300
Definition Window
;;discount: number number -> number
;helper function to compute percentage decrease
(define (discount percent money)
  (- money (* money (/ percent 100))))

;;cost: number -> number
;;compute cost with a discount of 10% on first $100, 15% on next 400,
;;    25% on next 500, 50% on any amount spent over 1000.
(define (cost $)
  (cond
    [(<= $ 100)  (discount 10 $)]
    [(<= $ 500)  (+ (discount 10 100)
                    (discount 15 (- $ 100)))]
    [(<= $ 1000) (+ (discount 10 100)
                    (discount 15 400)
                    (discount 25 (- $ 500)))]
    [(> $ 1000)  (+ (discount 10 100)
                    (discount 15 400)
                    (discount 25 500)
                    (discount 50 (- $ 1000)))]))

(cost 50)  = 45
(cost 100) = 90
(cost 200) = 175
(cost 500) = 430
(cost 600) = 500
(cost 1000) = 800
(cost 2000) = 1300

INVEST YOUR MONEY

Instead of spending your money, try investing your money. The only difference is:
  • the percentage rates are lower
  • and a percentage increase helper program is used which adds instead of subtracts.

    Home
    E-mail
    Lessons