  PROGRAM CHECK (TTY);
  (*       THIS PROGRAM BALANCES A CHECKBOOK

   THE FIRST PORTION VERIFIES CHECKBOOK ENTRIES SINCE LAST MONTH   *)
VAR
  NEWBALANCE      :REAL;
  BALANCE, ENTRY :REAL;
  CHECKSOUT,FC :REAL;
  BANKBALANCE,DEPOSITS : REAL;
  ANS  : CHAR;

 BEGIN
  BALANCE := 0 ;

  (* READ IN LAST VERIFIED BALANCE FROM TERMINAL *)
  WRITE (TTY, 'TYPE LAST MONTH''S BALANCE:') ; BREAK;
  READ (TTY, BALANCE) ;

  (* READ IN RECENT CHECKBOOK ENTRIES AND SHOW RUNNING BALANCE *)
  WRITELN (TTY, 'TYPE CHECK OR DEPOSIT VALUES ONE AFTER ANOTHER.') ;
  WRITELN (TTY, 'INDICATE A DEPOSIT BY PRECEDING IT WITH A HYPHEN.') ;
  WRITELN (TTY, 'TO STOP, ENTER A ZERO') ;
   REPEAT
    (* READ IN THE NEXT ENTRY, COMPUTE AND OUTPUT NEW BALANCE *)
    READ (TTY, ENTRY) ;
    BALANCE := BALANCE - ENTRY ;
    WRITELN (TTY, 'BALANCE=', BALANCE:9:2)
   UNTIL ENTRY = 0 ;
  WRITELN (TTY, 'FINAL BALANCE WAS ', BALANCE:9:2) ;
  WRITELN (TTY) ;

  (* THIS SECOND PORTION WILL RECONCILE THE CHECKBOOK WITH THE BANK STATEMENT *)
  WRITE (TTY, 'DO YOU WISH TO RECONCILE YOUR BANK STATEMENT? [Y/N]: ') ;
  BREAK ;
  READLN (TTY) ;
  READ (TTY, ANS);
  IF ANS = 'Y'
  THEN
   BEGIN
    WRITELN (TTY, 'WHAT IS THE FINANCE CHARGE SHOWN? ') ;
    BREAK ;
    READ (TTY, FC) ;
    IF FC <> 0
    THEN
     BEGIN
      BALANCE := BALANCE - FC ;
      WRITELN (TTY, 'ADJUST CHECKBOOK BALANCE TO', BALANCE:9:2)
     END;
    WRITELN (TTY, 'ENTER AMOUNTS OF EACH OUTSTANDING CHECK ONE BY ONE.');
    WRITELN (TTY, 'ENTER A ZERO WHEN THERE ARE NO MORE.') ;
    CHECKSOUT := 0 ;
     REPEAT
      READ (TTY, ENTRY) ;
      CHECKSOUT := CHECKSOUT + ENTRY
     UNTIL ENTRY = 0 ;
    WRITELN (TTY, 'ENTER ANY DEPOSITS NOT SHOWN ON STATEMENT');
    BREAK;
    DEPOSITS := 0;
     REPEAT
      READ (TTY, ENTRY);
      DEPOSITS := DEPOSITS + ENTRY
     UNTIL ENTRY = 0;
    WRITELN (TTY, 'WHAT IS THE ENDING BALANCE SHOWN ON THE STATEMENT?');
    READ (TTY, BANKBALANCE);
    NEWBALANCE := BANKBALANCE + DEPOSITS - CHECKSOUT;
    WRITELN (TTY);
    WRITELN (TTY, 'THE BANK BALANCE SHOWS ',NEWBALANCE:9:2) ;
    WRITELN (TTY, 'YOUR CHECKBOOK SHOWS ', BALANCE:9:2);
    IF BALANCE <> NEWBALANCE
    THEN
     IF NEWBALANCE < BALANCE
     THEN
      WRITELN (TTY,'THE BANK SHOWS ',BALANCE-NEWBALANCE:9:2, ' LESS '
	       ,'THAN YOU')
     ELSE
      WRITELN (TTY, 'THE BANK SHOWS ',NEWBALANCE-BALANCE:9:2,
	       ' MORE THAN YOU')
    ELSE WRITELN (TTY, 'CONGRATULATIONS, YOU BALANCED IT!')
   END;
 END.
