Loan Shark

Shark Title

A payment calculator for home use


by Marty Schmidt
16K cassette or 24K Disk

Almost everyone has, at one time or another, borrowed money. Loan Shark will enable you to calculate what the payments would be. "Big deal," you say. "Those programs are a dime a dozen."

Maybe so. Loan Shark, however, does more. A loan has four variables. They are: principal, interest rate, number of payments and payment amount. This program will compute any of them for you if you enter the other three.

Also, if you enter all four items, the remaining balance (or balloon payment) will be displayed. Each time you enter a set of data, all four items and the total interest paid will be displayed on the same line under their respective column headings. You can try many different combinations and compare results, since all data will remain on the screen.

Using Loan Shark.

To use the program, simply enter the values as they are requested at the bottom of the screen. Press RETURN without an entry to skip the unknown item. When entering the principal and number of payments data, you can enter two values separated by a plus, minus, multiplication or division sign.

This can save time, as you enter the number of years times twelve for the number of payments, without having to figure it out in advance. It's very handy when using data with a long repayment schedule (a home loan). You can enter the original amount minus the down payment when you are prompted for the principal, another timesaver.

In the unlikely event that you should fill the screen and then enter, more data, you will receive a prompt to turn your printer on, if you have one - or else copy the numbers you want to save. When you proceed, the screen will clear. If you do have a printer, the column headings and all data will be printed. The data can be printed at any time by entering P when prompted for the principal or number of payments.

The program.

The colors for the display were generated using Richard Kalagher's Multiple Screen Generator (in ANALOG Computing's issue 12).

Loan Shark uses graphics 0 with a text window. To employ this technique, first open a channel to write to the screen (OPEN #6,8,0,"S:"), then you can POKE 703,4. When you print to the upper twenty lines, use a PRINT #6 command. The top lines will not scroll with the bottom four lines, but will remain on the screen. The text window can then be used for input prompts and other instructions, and cleared with a simple clear screen command.

Following are three subroutines from this program which can, with minor changes, be incorporated into your programs.

1. (Lines 90 210) Format output, similar to a PRINT USING command in some BASICs.

Before the subroutine is called, set PIC$ equal to the format you want. Put the decimal point where you wish and include a dollar sign and/or trailing zeros, if desired. Set NU equal to the number you want formatted. Call the subroutine and PRINT FRM$ (Lines 870-960). Your number will be rounded to the number of places to the right of the decimal in PIC$ and trailing zeros will be added if you included them in PIC$.

Using this sbroutine, you can right justify, add trailing zeros, round off and include any special characters, all in one step. This is the most versatile formatting routine I have seen for the Atari.

2. (Lines 230-340) Two number input.

The BASIC on my pocket computer enables me to enter a series of numbers separated by arithmetic operators, all in one step. For instance, you can enter 247-119, and the value 128 will be entered. Atari BASIC does not allow this, so I wrote a simple subroutine enabling entry of a sign (+, -, *, /) between two numbers. You input to Q$, call the subroutine, and the variable X contains the result.

This subroutine, as used here, also checks for the print (P) and quit (Q) commands. Since it's used only when entering the principal and number of payments, the print and quit commands will only be recognized when entering these values.

3. (Lines 1040-1140) Graphics 0 screen dump.

This subroutine creates TEXT$ from a screen line, character by character. The outer FOR-NEXT loop contains the rows to be read, and the inner loop reads the columns. The column and row values can be changed so only part of the screen is sent to the printer. The inverse control T characters in Line 1100 are to underline the headings using a C.Itoh Prowriter. If you have a different printer, this character may have to be changed accordingly.

Here's a brief outline of the Loan Shark program.

Lines 90-210 - Right justify output and add trailing zeros.
Lines 230-340 - Allow two-number input, separated by +, -, *, or /.
Line 360 - Compute payment.
Lines 370-400 - Print heading and instruction lines.
Line 410 - Start of main program.
Lines 440-590 - Input data.
Line 610 - Compute principal.
Lines 650-730 - Compute interest rate using trial and error method.
Line 750 - Compute number of payments.
Line 810 - Compute balloon payment.
Line 830 - Compute total interest.
Lines 860-1020 - Print data to the screen.
Lines 1040-1140 - Print screen to printer
Lines 1150-1220 - Prompts to turn printer on or copy data to avoid loss.
Lines 1230-1260 - Clear screen of data.
Lines 1280-1520 - Screen color generator.

There you are. I hope Loan Shark helps you stay out of the hands of the Big Boys.


Marty Schmidt has been a pattern maker by trade, for twenty-one years. He's had an Atari 800 for the past two and one-half years and has been using it for family financial and record-keeping purposes, word processing and - let's not forget - entertainment.


Listing 1.
BASIC listing.

50 REM ************************
51 REM *      LOANSHARK       *
52 REM *         BY           *
53 REM *    MARTY SCHMIDT     *
54 REM ************************
80 OPEN #6,8,K0,"S:":OPEN #2,4,K0,"S:"
90 A=34:POKE 559,K0:GOSUB 30000:POKE 7
12,186:POKE 559,A:GOTO 1000
95 REM FORMAT NUMBERS
100 FD=K0:FRM$=PIC$
110 FOR J=1 TO LEN(FRM$)
120 IF FRM$(J,J)="." THEN FD=LEN(FRM$)
-J:GOTO 140
130 NEXT J
140 IF FD=K0 THEN NUM$=STR$(INT(NU+0.5
)):GOTO 180
150 H=INT(10^FD+0.5)
160 NU=INT(NU*H+0.5)/H
170 NUM$=STR$(NU)
180 FOR K=1 TO LEN(NUM$)
190 IF NUM$(K,K)="." THEN 210
200 NEXT K
210 FRM$(J-K+1,J-K+LEN(NUM$))=NUM$
220 RETURN 
300 REM INPUT ROUTINE
310 FOR L=1 TO LEN(Q$):W=ASC(Q$(L,L))
320 IF W=46 THEN 350
330 IF W=81 THEN POP :GRAPHICS K0:POKE
 82,2:NEW 
335 IF W=80 THEN TRAP 5300:GOSUB 5010:
POP :GOTO 1040
340 IF W<48 OR W>57 THEN 370
350 NEXT L
360 X=VAL(Q$):RETURN 
370 Y=VAL(Q$):Z=VAL(Q$(L+1,LEN(Q$)))
380 IF W=43 THEN X=Y+Z:RETURN 
390 IF W=45 THEN X=Y-Z:RETURN 
400 IF W=42 THEN X=Y*Z:RETURN 
410 IF W=47 THEN X=Y/Z:RETURN 
490 REM FIGURE PAYMENT
500 TEST=(P-B*(1+I)^-N)/((1-(1+I)^-N)/
I):RETURN 
600 POSITION K0,K0:? #6;" PRINCIPAL   
APR   #   PAYMENT TOTAL INT";:RETURN 
700 POSITION K0,19:? #6;"RETURN TO SKI
P : P TO PRINT : Q TO QUIT";:RETURN 
1000 POKE 82,K0:POKE 703,4:POKE 755,K0
:GOSUB 600:GOSUB 700
1010 DIM PIC$(15),FRM$(15),NUM$(15),Q$
(30),TEXT$(1000)
1030 REM INPUT DATA
1040 P=K0:Q=K0:N=K0:M=K0:TRAP 1300:GOS
UB 700:POSITION K0,20:? "      PRINCI
PAL ";
1045 POKE 85,20:INPUT Q$:IF Q$="" THEN
 X=K0:GOTO 1060
1050 GOSUB 300
1060 P=X:B=K0
1070 TRAP 1080:? "       ANNUAL % ";:P
OKE 85,20:INPUT Q:I=Q/1200
1080 TRAP 1300:? "NO. OF PAYMENTS ";:P
OKE 85,20:INPUT Q$:IF Q$="" THEN X=K0:
GOTO 1100
1090 GOSUB 300
1100 N=X:TRAP 1200:? "        PAYMENT 
";:POKE 85,20:INPUT M
1200 TRAP 1300:? "":COLOR 32:PLOT K0,
19:DRAWTO 39,19:IF P=K0 THEN 1400
1210 IF Q=K0 THEN 1500
1220 IF N=K0 THEN 1600
1230 IF M=K0 THEN 1700
1240 GOTO 1800
1300 ? "   IMPROPER VALUE!":FOR I=1
TO 400:NEXT I
1310 ? :? "  PLEASE TRY AGAIN.":FOR I
=1 TO 400:NEXT I
1320 GOTO 1040
1390 REM FIGURE PRINCIPAL
1400 P=M*((1-(1+I)^-N)/I)+(B*(1+I)^-N)
1410 GOTO 1900
1490 REM FIGURE INTEREST RATE
1500 POKE 559,K0:Q=Q+1:I=Q/1200:GOSUB 
500:IF TEST=M THEN POKE 559,A:GOTO 190
0
1510 IF TEST>M THEN Q=Q-1:GOTO 1530
1520 GOTO 1500
1530 Q=Q+0.1:I=Q/1200:GOSUB 500:IF TES
T=M THEN POKE 559,A:GOTO 1900
1540 IF TEST>M THEN Q=Q-0.1:GOTO 1560
1550 GOTO 1530
1560 Q=Q+0.01:I=Q/1200:GOSUB 500:IF TE
ST>=M THEN POKE 559,A:GOTO 1900
1570 GOTO 1560
1590 REM FIGURE NUMBER OF PAYMENTS
1600 N=LOG((M-I*B)/(M-I*P))/LOG(1+I)
1610 GOTO 1900
1700 GOSUB 500:M=TEST
1710 GOTO 1900
1800 B=(P-M*(1-(1+I)^-N)/I)/((1+I)^-N)
1810 FLAG=1
1900 INT=M*N-(P-B)
1990 REM PRINT DATA TO SCREEN
2000 LINE=LINE+1:IF LINE>(18-(FLAG=1))
 THEN GOSUB 5000:LINE=K0:GOSUB 6000:GO
TO 2000
2005 POSITION K0,LINE:PIC$="$       .0
0":NU=P:GOSUB 100
2010 ? #6;FRM$;
2020 PIC$="|  .00":NU=Q:GOSUB 100
2030 ? #6;FRM$;
2040 PIC$="|   ":NU=N:GOSUB 100
2050 ? #6;FRM$;
2060 PIC$="|$    .00":NU=M:GOSUB 100
2070 ? #6;FRM$;
2080 PIC$="|$     .00":NU=INT:GOSUB 10
0
2090 ? #6;FRM$;
2100 IF FLAG=1 THEN 3000
2170 GOSUB 700:GOTO 1040
3000 FLAG=K0
3010 PIC$="$       .00":NU=B:GOSUB 100
3020 LINE=LINE+1:POSITION K0,LINE:? #6
;"PAYOFF AMOUNT FOR ABOVE IS   ";FRM$;
3040 GOTO 2170
4990 REM PRINT DATA TO PRINTER
5000 TRAP 5200
5010 POKE 54286,64:FOR ROW=K0 TO 18:PO
SITION PEEK(82),ROW
5020 FOR COL=1 TO 40:GET #2,CHAR:TEXT$
(COL,COL)=CHR$(CHAR)
5030 NEXT COL:GET #2,COL
5035 IF TEXT$(1,2)="  " THEN 5100
5040 LPRINT TEXT$
5045 IF ROW=K0 THEN LPRINT "..........
..............................":GOTO 5
050
Line 5045
5046 LPRINT 
5050 NEXT ROW
5100 POKE 54286,192:RETURN 
5200 POSITION K0,19:? #6;"       PRESS
 ANY KEY TO CONTINUE.      ";
5205 POKE 54286,192:? "    THERE IS N
O PRINTER ON LINE!!":? "  IF YOU PROCE
ED WITHOUT A PRINTER THE"
5210 ? "  DATA NOW ON THE SCREEN WILL 
BE LOST."
5220 OPEN #3,4,K0,"K:":GET #3,KEY:CLOS
E #3
5230 TRAP 5100:GOTO 5010
5300 POSITION K0,19:? #6;"       PRESS
 ANY KEY TO CONTINUE.      ";
5310 ? "        TURN YOUR PRINTER ON
":? "   IF YOU WANT THE ABOVE DATA PRI
NTED!!"
5320 POKE 54286,192:GOTO 5220
6000 FOR ROW=1 TO 18
6010 COLOR 32:PLOT K0,ROW:DRAWTO 39,RO
W
6020 NEXT ROW
6030 RETURN 
30000 REM INITIALIZE SCREEN
30005 RESTORE 30170:FOR N=K0 TO 99:REA
D X:POKE 1664+N,X:NEXT N
30010 COLTAB=1712:LUMTAB=COLTAB+24
30014 X=USR(1693)
30030 POKE 512,128
30040 POKE 513,6
30060 DSTART=PEEK(560)+256*PEEK(561)
30070 FOR N=DSTART+6 TO DSTART+28
30080 POKE N,130
30090 NEXT N
30100 POKE DSTART+3,194
30120 POKE 54286,192
30125 PRINT CHR$(125)
30140 POKE 710,PEEK(COLTAB)
30150 POKE 709,PEEK(LUMTAB)
30160 RETURN 
30170 DATA 72,138,72,174,156,6,189,176
,6,141
30180 DATA 10,212,141,24,208,189,200,6
,141,23
30190 DATA 208,238,156,6,104,170,104,6
4,14,104
30200 DATA 169,7,160,168,162,6,32,92,2
28,96
30210 DATA 169,1,141,156,6,76,98,228,1
62,170
30220 DATA 156,170,156,170,156,170,156
,170,156,170
30230 DATA 156,170,156,170,156,170,156
,162,204,204
30240 DATA 204,204,14,0,0,0,0,0,0,0
30250 DATA 0,0,0,0,0,0,0,0,0,0
30260 DATA 0,14,0,0,0,0,0,0,0,0

CHECKSUM DATA.
(see C:CHECK, D:CHECK or Unicheck)

50 DATA 275,615,999,968,287,293,752,15
2,741,140,177,739,486,511,5,7140
170 DATA 235,189,389,734,411,589,79,77
0,498,391,776,749,753,56,550,7169
380 DATA 222,233,196,219,385,964,575,5
47,405,235,892,444,582,724,963,7586
1070 DATA 581,693,728,938,565,932,933,
936,714,393,513,715,799,212,718,10370
1490 DATA 95,523,442,718,544,948,727,5
80,735,924,328,724,847,727,278,9140
1810 DATA 419,338,958,247,676,812,97,8
14,957,816,289,818,653,820,939,9653
2170 DATA 14,679,113,79,722,213,681,43
8,525,241,714,383,200,811,87,5900
5100 DATA 485,966,555,836,66,963,969,9
93,428,645,327,86,792,878,847,9836
30010 DATA 738,173,237,201,593,575,213
,687,991,348,788,544,595,57,670,7410
30180 DATA 830,76,821,689,247,241,637,
233,497,4271


Previous | Next

Original text copyright 1984 by ANALOG Computing. Reprinted with permission by the Digital ANALOG Archive.