woonie

make-secure-account

Oct 2nd, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.76 KB | None | 0 0
  1. (define tries 7)
  2. (define bal 0)
  3. (define password1 0)
  4. (define (make-secure-account password balance)
  5.   (set! password1 password)
  6.   (set! bal balance)
  7.   (define (object pw withdraw)
  8.     (cond ((not (equal? password1 pw)) (begin (set! tries (- tries 1))
  9.                                               (if (<= tries 0)
  10.                                                   (call-the-cops)
  11.                                                   "Wrong password!")))
  12.           ((>= bal withdraw) (begin (set! bal (- bal withdraw))
  13.                                     (set! tries 7)
  14.                                     bal))
  15.           (else (begin (set! tries 7)
  16.                        "Insufficient funds!"))))
  17.   object)
  18.  
  19. ; (define test1 (make-secure-account 12345 1000))
  20.  
Advertisement
Add Comment
Please, Sign In to add comment