# what's wrong with this

When I choose deposit, say \$200, the answer comes out in the 4,000 range. I think the case w of statement is putting me in an infinite loop. Everytime I choose withdrawal and withdrawal, it'll go into an infinite loop. I haven't even tried the see_balance procedure yet.

var balance: integer;
balance := \$1,000;

begin
writeln ('MENU OF CHOICES');
writeln (' 1) Deposit');
writeln (' 2) Withdrawal');
writeln (' 3) See balance');
writeln (' 4) Quit');

procedure Deposit;
var d: integer;
begin
write ('How much do you want to deposit?');
balance := balance + d;
end; {Deposit};

procedure Withdrawal;
var w: integer;
amount: integer;

begin
write ('How much do you want to withdrawal?');
write ('\$50');
write ('\$100');
write ('\$200');
write ('\$500');

case w of
1 : amount := 50;
2 : amount := 100;
3 : amount := 200;
4 : amount := 500
end; {case}
balance := balance - amount
end; {Withdrawal}

procedure {See_balance}
begin
writeln ('Your balance is ' , balance);
end; {See_balance}

begin {main}
repeat
write ('Enter choice ');
case choice of
1 : Deposit;
2 : Withdrawal;
3 : See_balance;
4 : {quit the loop}
else writeln ('Invalid choice -- choose again')
end; {case}
writeln
until choice = 4
end.

###### Who is Participating?

Systems EngineerCommented:
CONST
balance: integer = 1000;

begin
writeln ('MENU OF CHOICES');
writeln (' 1) Deposit');
writeln (' 2) Withdrawal');
writeln (' 3) See balance');
writeln (' 4) Quit');

procedure Deposit;
var
d: integer;
begin
write ('How much do you want to deposit?');
balance := balance + d;
end; {Deposit};

procedure Withdrawal;
var
w: integer;
amount: integer;
begin
write ('How much do you want to withdrawal?');
write ('\$50');
write ('\$100');
write ('\$200');
write ('\$500');
case w of
1 : amount := 50;
2 : amount := 100;
3 : amount := 200;
4 : amount := 500
end; {case}
If balance > amount Then
balance := balance - amount
else
Begin
WriteLn('You don't have that kind of money');
WriteLn('Do you think we're stupid to give you money, you moron');
WriteLn('Thanks for your preference');
End
end; {Withdrawal}

procedure See_balance
begin
writeln ('Your balance is ' , balance);
end; {See_balance}

begin {main}
repeat
write ('Enter choice ');
case choice of
1 : Deposit;
2 : Withdrawal;
3 : See_balance;
4 : {quit the loop}
else writeln ('Invalid choice -- choose again')
end; {case}
writeln
until choice = 4
end.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.