Solved

what's wrong with this

Posted on 2000-04-11
1
164 Views
Last Modified: 2011-09-20
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;


procedure PRINTMENU;
   begin
        writeln ('MENU OF CHOICES');
        writeln (' 1) Deposit');
        writeln (' 2) Withdrawal');
        writeln (' 3) See balance');
        writeln (' 4) Quit');
   end; {PRINTMENU}

procedure Deposit;
  var d: integer;
  begin
     write ('How much do you want to deposit?');
     readln (d);
       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');
     readln (w);

     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
     PRINTMENU;
     write ('Enter choice ');
     readln (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
Comment
Question by:kazooie21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 6

Accepted Solution

by:
My name is Mud earned 30 total points
ID: 2706729
CONST
  balance: integer = 1000;

procedure PRINTMENU;
begin
  writeln ('MENU OF CHOICES');
  writeln (' 1) Deposit');
  writeln (' 2) Withdrawal');
  writeln (' 3) See balance');
  writeln (' 4) Quit');
end; {PRINTMENU}

procedure Deposit;
var
  d: integer;
begin
  write ('How much do you want to deposit?');
  readln (d);
  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');
  readln (w);
  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
    PRINTMENU;
    write ('Enter choice ');
    readln (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

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
In this blog we highlight approaches to managed security as a service.  We also look into ConnectWise’s value in aiding MSPs’ security management and indicate why critical alerting is a necessary integration.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question