doubt in MIT scheme

Asked by sameer

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

English Edit question
Ubuntu mit-scheme Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Bhavani Shankar (bhavi) said :

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


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.