Solved

what's wrong with this

Posted on 2000-04-11
1
155 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
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
printers log data 3 356
Unsigned int64 to unsigned int32 10 1,630
Android Application not running 1 485
Virtuailstring tree compare node issue 14 90
In this article, I will show you HOW TO: Suppress Configuration Issues and Warnings Alert displayed in Summary status for ESXi 6.5 after enabling SSH or ESXi Shell.
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

759 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now