USING: io kernel math math.parser ; IN: payments : interest-rate ( -- rate ) .02 12 / ; : initial-balance ( -- balance ) 500 ; : total-to-pay ( -- amt ) 587 ; : number-of-payments ( -- n ) 6 ; : monthly-payment ( -- payment ) total-to-pay number-of-payments / ; : collect-interest ( rate balance -- rate balance ) 2dup * + ; : payment ( rate balance payment -- rate balance payment ) [ collect-interest ] dip [ - ] keep ; : do-it ( -- ) interest-rate initial-balance monthly-payment number-of-payments [ payment ] times rot 2drop number>string print ;