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
|
|||||||
Interaction Window
Welcome to DrScheme, |
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
|
||||||