home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l196 / 3.ddi / CHECK.BA$ / CHECK.bin
Encoding:
Text File  |  1990-06-24  |  1.6 KB  |  55 lines

  1. DIM Amount(1 TO 100) AS CURRENCY, Balance AS CURRENCY
  2. CONST FALSE = 0, TRUE = NOT FALSE
  3. CLS
  4. ' Get account's starting balance:
  5. INPUT "Type starting balance, then press <ENTER>: ", Balance
  6. ' Get transactions. Continue accepting input
  7. ' until the input is zero for a transaction,
  8. ' or until 100 transactions have been entered:
  9. FOR TransacNum% = 1 TO 100
  10.    PRINT TransacNum%;
  11.    PRINT ") Enter transaction amount (0 to end): ";
  12.    INPUT "", Amount(TransacNum%)
  13.    IF Amount(TransacNum%) = 0 THEN
  14.       TransacNum% = TransacNum% - 1
  15.       EXIT FOR
  16.    END IF
  17. NEXT
  18.  
  19. ' Sort transactions in ascending order,
  20. ' using a "bubble sort":
  21. Limit% = TransacNum%
  22. DO
  23.    Swaps% = FALSE
  24.    FOR I% = 1 TO (Limit% - 1)
  25.       ' If two adjacent elements are out of order,
  26.       ' switch those elements:
  27.       IF Amount(I%) < Amount(I% + 1) THEN
  28.          SWAP Amount(I%), Amount(I% + 1)
  29.          Swaps% = I%
  30.       END IF
  31.    NEXT I%
  32.   ' Sort on next pass only to where last switch was made:
  33.   Limit% = Swaps%
  34.  
  35. ' Sort until no elements are exchanged:
  36. LOOP WHILE Swaps%
  37. ' Print the sorted transaction array. If a transaction
  38. ' is greater than zero, print it as a "CREDIT"; if a
  39. ' transaction is less than zero, print it as a "DEBIT":
  40. FOR I% = 1 TO TransacNum%
  41.    IF Amount(I%) > 0 THEN
  42.       PRINT USING "CREDIT: $$#####.##"; Amount(I%)
  43.    ELSEIF Amount(I%) < 0 THEN
  44.       PRINT USING "DEBIT: $$#####.##"; Amount(I%)
  45.    END IF
  46.    ' Update balance:
  47.    Balance = Balance + Amount(I%)
  48. NEXT I%
  49. ' Print the final balance:
  50. PRINT
  51. PRINT "--------------------------"
  52. PRINT USING "Final Balance: $$######.##"; Balance
  53. END
  54.  
  55.