CASH FLOW (16K ZX-81)
By Ron Cavers
from Personal Computing Today, March 1983, pages 30-32

Keep your cash floing smoothly with Ron Caver's analysis program.

If you want to know which month you will have cash to spare, or which month you
are likely to find a nasty letter from your bank manager on your doormat, then
Cash Flow is the program for you.

The program is not designed to show your current state of affairs to the penny,
but rather an assessment of your monthly requirements and likely bank balance,
the nearest pound, over any given calendar year. As with similar programs,
expense and salary data can be altered to allow you to explore 'what-if'
situations.

Enter RUN 1810 and you will see a prompt for the number of expense categories.
This has an upper limit of eleven to keep the display routine simple and should
be adaquate for general household expenses. When you receive the prompts to
enter the category names, you will have six spaces each and some suggestions
for these are shown with the variables list. When the final name is entered,
you will be invited to SAVE the listing and afterwards the option to view the
data is given. If you wish, this is a good point to STOP the program and
deleted the now superfluous lines (1800 to 2200) used for initialisation - this
is purely to save those precious seconds when SAVEing and LOADing and they will
not affect the running of the program if left in the listing. (Note: if you do
delete these lines, restart the program by GOTO 1060 and not by RUN.)

Having got back to the option to see the data, press NEWLINE and after a few
seconds you should see a display showing your expense and various other
headings on the left, then totals for each category for January, February and
March, followed by a total column on the right which will display the yearly
totals. By entering the command 'V' for view and month number you can change
the display to see any set of three consecutive months. The end column will
always display the yearly totals. At present all the totals will be set to zero
and the next step is to enter your expected spending requirements for the
calendar year. Enter command 'C' for change and then follow the screen prompts
- some useful hints are:

a) Deal first which those categories which have a fixed monthly figure - eg if
you have standing orders of 100 to pay from March to December, then when
prompted, enter month number 3 to start and month 12 to end. The category
number and amount then completes the entry for the entire ten months.

b) One-off expected bills are best entered a month at a time - eg for February
enter month 2 to start and month 2 to end. Then you can enter or amend as manay
category totals as you wish for that month.

c) The first time you use the command 'C', you will need to enter your opening
cash or bank balance for January - this is the only total balance that the
program will allow you to directly access, all the others are calculated by the
program.

d) The program will accept NEWLINE for zero entries. The display totals will
remain at zero during this operation but once completed, and the display
requested, the totalling routine at line 40 is called and the current display
is cleared and reinstated, shwoing all the new totals.

As you progress through the year, each months budgetted figures can be adjusted
to reflect your actual spending, and the estimated future balances will be
re-calculated accordingly. (The SAVE 'S' command should be used at this point
so that you can preserve the data for the following months updates).

If your expenses exceed your salary for any given month, your net income will
be shown as a minus figure - as will your actual balances if you 'go into the
red'. When you approach the end of the calendar year, simply set up another
file using the basic program listing first SAVEd, and enter the projected
closing balance for the current year as the opening balance for your new year
predictions. The program will run on the ZX80 (8K ROM) without conversion, as
it is best run in FAST mode to avoid long delays during totalling and printing
the full data. However, if you own a ZX81 and prefer a steady screen during
input, run the program in SLOW mode with the following changes:

1570 FAST
1575 GOSUB 110
1195 SLOW
1935 SLOW
2185 FAST


HOW IT RUNS

100-340   TOTALLING ROUTINE
110-130   Reset to zero, years totals for expenses, salary and net income.
140       Loop to count month's.
150       Reset each month's expense total to zero.
160-180   Loop to toal each expense category for the month.
190       Add each month's salary into years total.
200       Calculate net income for the month.
210       Calculate closing balance for the month.
220       Add net monthly income into years total.
230       Add total monthly expenses into years total.
240       Transfer closing balance each month to opening balance next month except December.
260-310   Loop to total each expense category for the year.
270       Reset each expense category year total to zero.
280-300   Loop to add each expense category across to find total for year.
320-330   Transfer January opening balance and December closing balance to total column.
350-370   RULE A LINE FOR DISPLAY
400-480   VERIFY DATA ROUTINE
420       Accepts NEWLINE for zero.
430-470   Ensures input is an integer between 0 and 999.
1000-1070 SAVE DATA SECTION
1080-1210 DISPLAY DATA SECTION
1100      Print three month's headings.
1110      Call 'Rule a line' routine.
1120-1190 Loop to print each category name held in C$ array and all data held in A array.
1140-1170 Measures the length of each element of the data array, as if it were a string, and tabulates the
          printing so that the numbers are justified from the right.
1180      Call 'Rule a line' routine.
1200      Commands available.
1220-1260 SELECT COMMAND CHOSEN
1270-1330 CHANGE VIEW OF DISPLAY
1290-1300 Verify input as a month number.
1320      Adjust, if required, to avoid display crash. (If M was set to 11 or 12, the program would attempt to
          print months 13 and 14 at lines 1100, 1150 and 1160).
1330      Pass control to display section.
1340-1590 CHANGE/ENTER DATA
1350-1360 Prompt for a starting month number.
1370-1400 Verify input as a month number, or zero.
1380      If input is zero, returns control to display section, after totalling all data.
1410      Prompt for an end of month number.
1420-1450 Verify input as a month number.
1460-1470 Prompt for a category number.
1480-1500 Verify input as a category number, or zero.
1485      If input is zero, returns control to start month prompt.
1490      Prevent access to totals and balances except for January opening balance.
1510      Prompt for new amount.
1520      Verify input.
1530-1550 Loop to enter new amount into the category specified, for the month(s) specified.
1560      Pass control back to category number prompt.
1570      Call 'Totalling' routine.
1580      Adjust to avoid display crash.
1590      Pass control to display section.
1800-2200 INITIALISATION
1810      Prompt for number of categories.
1820-1830 Verify input.
1850      Set E as number of expense categories.
1860-1900 Set pointers for position in data array of totals and balances.
1910-1930 Dimensions arrays.
1940-1960 Loop to prompt and accept input for category names.
1970-1990 Category numbers automatically entered into C$ array.
2010-2070 Total and other headings set into C$ array.
2080-2140 Set month names into M$ array.
2160-2190 Save program list with arrays.
2200      Pass control to the display section.

Note:All statements to PRINT AT line 20 to 21, should contain 32 characters, so
spaces should be added where necessary to ensure the screen prompts overwrite
one another. The exception is statement number 1410 which needs 19 space after
the "?".
