home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / tools / xref / basxrf / amort.bas next >
BASIC Source File  |  1994-06-03  |  6KB  |  201 lines

  1. 'AMORT.BAS       Copyright 1993 by JN Goodale
  2. 'Date: [93-12-20]
  3. '
  4. '   Use to demonstrate BASICXR Cross-Reference program.
  5. '
  6. 'Desc: Amortization of a Loan - Find Amount of Level Payment
  7. '
  8. '
  9. '      P=Principal
  10. '      R=Interest Rate
  11. '      I=Interest/Period
  12. '      N=Number of Payments (Periods)
  13. '      A=Amount of Level Payment
  14. '
  15. '
  16. '
  17. '                 P * I
  18. '        A =   --------------
  19. '                      1
  20. '              1 -  --------
  21. '                   (1+I) ^N           Where ^N is "to the Nth Power"
  22. '
  23. '.......................................................................
  24.  
  25. DIM text$(24)
  26. text$(1) = "                             [ LOAN AMORTIZATION ]"
  27. text$(2) = " "
  28. text$(3) = "      Calculate a Level Loan Payment, given:"
  29. text$(4) = ""
  30. text$(5) = "          Loan Principal, nearest full $  (Max 500000, no commas)"
  31. text$(6) = "          Interest Rate per Year (Max 30.00), Full %, as in 7.75% = 7.75"
  32. text$(7) = "          Number of months to Pay  (Max 480)"
  33. text$(8) = "                I.E. 30 Years = 360 Months"
  34. text$(9) = "                      4 Years =  48 Months"
  35. text$(10) = STRING$(80, 220)
  36. text$(11) = "      Enter Amount of PRINCIPAL:             (Q-to Quit)"
  37. text$(12) = "          Enter Interest Rate %: "
  38. text$(13) = "         Enter Number of Months: "
  39. text$(14) = " "
  40. text$(15) = "     The MONTHLY Payment on the above loan would be:  $"
  41. text$(16) = " "
  42. text$(17) = ""
  43. text$(18) = "              Total Interest: $           Total Payments: $"
  44. text$(19) = ""
  45. text$(20) = "          V-To View schedule      P-To Print schedule"
  46. text$(21) = "          Q-To Start Over"
  47. text$(22) = "                       Choice ? _"
  48. text$(23) = " "
  49. text$(24) = " "
  50.  
  51. DIM Heading$(3)
  52. Heading$(1) = "[ Loan Amortization ]    Principal:        Interest       Months      "
  53. Heading$(2) = "     Payment #   Balance      Interest     Principal"
  54. Heading$(3) = " "
  55.  
  56. E0$ = "#######": E2$ = "#######.##": EI$ = "####": FF$ = CHR$(13)
  57. ' Non=ASCI within Quotes
  58. DiskPic$(1) = "┌─────┐"
  59. DiskPic$(2) = "│     │"
  60. DiskPic$(3) = "└─────┘"
  61. DiskPic$(4) = "│     │"
  62.  
  63. ''.......................................................Page Eject
  64. StartProcess:
  65.     Principal$ = SPACE$(6)
  66.     InterestRate$ = SPACE$(5)
  67.     Months$ = SPACE$(3)
  68.  
  69. GetPrincipal:
  70.     CLS
  71.     FOR i = 1 TO 11: PRINT text$(i): NEXT i
  72.     LOCATE 11, 34: LINE INPUT Principal$
  73.     IF (Principal$ = "Q") OR (Principal$ = "q") THEN GOTO EndProgram
  74.     n = INSTR(Principal$, ".")
  75.     IF n THEN LSET Principal$ = LEFT$(Principal$, n - 1)
  76.     LOCATE 11, 34: PRINT Principal$;
  77.     Principal = VAL(Principal$)
  78.     IF Principal < 1 THEN GOTO StartProcess
  79.     IF Principal > 500000 THEN GOTO StartProcess
  80.     LOCATE 12, 1: PRINT text$(12)
  81.  
  82. GetInterest:
  83.     LOCATE 12, 35: LINE INPUT InterestRate$
  84.     IF (InterestRate$ = "q") OR (InterestRate$) = "Q" THEN GOTO EndProgram
  85.     InterestRate = VAL(InterestRate$) / 1200
  86.     IF (InterestRate < 0) OR (InterestRate > 30 / 1200) THEN
  87.         LOCATE 12, 35
  88.         PRINT SPACE$(10);
  89.         GOTO GetInterest
  90.     END IF
  91.     LOCATE 13, 1: PRINT text$(13)
  92.  
  93. GetMonthsToPay:
  94.     LOCATE 13, 35: LINE INPUT Months$
  95.     IF (Months$ = "q") OR (Months$ = "Q") THEN GOTO EndProgram
  96.     Months% = VAL(Months$) \ 1
  97.     Months = Months%
  98.     IF (Months% < 1) OR (Months% > 480) THEN
  99.         LOCATE 13, 35
  100.         PRINT SPACE$(10);
  101.         GOTO GetMonthsToPay
  102.     END IF
  103.  
  104.     MID$(Heading$(1), 37) = Principal$
  105.     MID$(Heading$(1), 53) = InterestRate$
  106.     MID$(Heading$(1), 67) = Months$
  107.  
  108. ' CalculateAmount
  109.     x = (1 + InterestRate) ^ Months%
  110.     y = 1 / x
  111.     z = 1 - y
  112.     Amount = (Principal * InterestRate) / z
  113.  
  114. PrintAmount:
  115.     LOCATE 15, 1
  116.     FOR i = 15 TO 23: PRINT text$(i): NEXT i
  117.     LOCATE 15, 57: PRINT USING E2$; (Amount);
  118.     TotalInterest = 0: TotalPayments = Months% * Amount
  119.     Balance = Principal
  120.     FOR i% = 1 TO Months%
  121.         InterestPay = Balance * InterestRate
  122.         PrincipalPay = Amount - InterestPay
  123.         Balance = Balance - PrincipalPay
  124.         IF Balance < 0 THEN
  125.             TotalPayments = TotalPayments + Balance
  126.             Balance = 0
  127.         END IF
  128.         TotalInterest = TotalInterest + InterestPay
  129.     NEXT i%
  130.     LOCATE 18, 32: PRINT USING E2$; TotalInterest;
  131.     LOCATE 18, 60: PRINT USING E2$; TotalPayments;
  132.  
  133. GetChoice:
  134.     LOCATE 22, 33
  135.     LINE INPUT k$
  136.     k$ = UCASE$(k$)
  137.     IF k$ = "Q" THEN GOTO StartProcess
  138.     IF k$ = "V" THEN GOSUB ViewLoanTable
  139.     IF k$ = "P" THEN GOSUB PrintLoanTable
  140.     CLS
  141.     GOTO PrintAmount
  142.  
  143. EndProgram:
  144.     CLS
  145.     END
  146. '>..............................................Start Selected Printing
  147. ViewLoanTable:
  148.     GOSUB HeadUpTableX: Balance = Principal
  149.     FOR i% = 1 TO Months%
  150.         InterestPay = Balance * InterestRate
  151.         PrincipalPay = Amount - InterestPay
  152.         Balance = Balance - PrincipalPay
  153.         Row = Row + 1
  154.         IF Row > 22 THEN GOSUB HeadUpTable
  155.         IF k$ = "Q" THEN RETURN
  156.         PRINT "          ";
  157.         PRINT USING EI$; (i%); : PRINT "   ";
  158.         PRINT USING E0$; Balance; : PRINT "    ";
  159.         PRINT USING E2$; InterestPay; : PRINT "    ";
  160.         PRINT USING E2$; PrincipalPay
  161.     NEXT i%
  162.     GOSUB HeadUpTable
  163.     RETURN
  164. '<............................................... End Selected Listing
  165. PrintLoanTable:
  166.     GOSUB HeadUpPrintX: Balance = Principal
  167.     FOR i% = 1 TO Months%
  168.         InterestPay = Balance * InterestRate
  169.         PrincipalPay = Amount - InterestPay
  170.         Balance = Balance - PrincipalPay
  171.         Row = Row + 1
  172.         IF Row > 52 THEN GOSUB HeadUpPrint
  173.         LPRINT TAB(10); USING EI$; (i%); : LPRINT "   ";
  174.         LPRINT USING E0$; Balance; : LPRINT "    ";
  175.         LPRINT USING E2$; InterestPay; : LPRINT "    ";
  176.         LPRINT USING E2$; PrincipalPay
  177.     NEXT i%
  178.     LPRINT FF$
  179.     RETURN
  180.  
  181. HeadUpTable:
  182.     PRINT
  183.     PRINT TAB(20); "Q-To Quit,   Any Other Key to Continue ......";
  184. GetAKey:
  185.     k$ = INKEY$
  186.     IF k$ = "" THEN GOTO GetAKey
  187.     k$ = UCASE$(k$)
  188. HeadUpTableX:
  189.     CLS
  190.     IF k$ = "Q" THEN RETURN
  191.     FOR Row = 1 TO 3: PRINT Heading$(Row): NEXT Row
  192.     RETURN
  193.  
  194. HeadUpPrint:
  195.     LPRINT FF$
  196. HeadUpPrintX:
  197.     FOR Row = 1 TO 3: LPRINT Heading$(Row): NEXT Row
  198.     LPRINT " "
  199.     RETURN
  200.  
  201.