doubt in MIT scheme

Asked by sameer on 2009-03-11

I don't understand how this one works.

(define balance 1000)
(define (withdraw amount)
  (if (or (< amount balance) (= amount balance))
      (begin (set! balance (- balance amount)) balance) "Insufficient amount"))

If I type (withdraw 50) the output is 950.
and again if i type (withdraw 50) the output is 900.
My doubt is that again it should print 950.

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu mit-scheme Edit question
Assignee:
No assignee Edit question
Last query:
2009-03-11
Last reply:
2009-03-12
Bhavani Shankar (bhavi) said : #1

Nopes Its right

you have defined balance as 1000 and you have defined it as balance - withdraw amount in simple sense looking at the above snippet.

So once if you type withdraw 50 o/p is 950

and again you are giving withdraw 50 from the new balance amount of 950

So the o/p naturally will be 900

Regards

Can you help with this problem?

Provide an answer of your own, or ask sameer for more information if necessary.

To post a message you must log in.