SUMS (1K ZX81)
by M N Scarlett, Maidenhead, Berkshire
from Your Computer, December 1981, Page 75

The idea for this program originated from the Mathematics program in the
Sinclair software catalogue, but it is a considerable improvement -
particularly in the way the program seems friendly to the user. The user
begins by entering his name which appears during the program run and the
computer acknowledges by printing "Hello, I am the ZX-81" on the screen.

The function required, +-*/, is entered directly, rather than via a numeric
code and then the user is asked by name for the level of difficulty he
requires. Levels 1, 2 and 3 are offered on the screen but any numeric value
can be inputted. 1, 2 and 3 produce sums capable of solution by mental
arithmetic.

Lines 130 and 140 derive the two variables used in the question, "C" is
related to "D" so that a negative result cannot be produced and in division
the answer will always be a whole number. Line 150 assembles the sum into a
string which is printed on the screen together with "=". This string
consists of the variable "D" with the operator entered earlier, and the
variable "C".

If the answer entered in response to printing the sum on the screen is
correct, the score variable "S" is incremented and the user is told by name
that his answer is correct and the score out of the number of sums attempted
so far is printed. After a delay, the screen clears and a new sum is
presented.

If the answer is wrong, "Wrong" appears on the screen and the sum is
reprinted with the correct answer. For extra impact, "Wrong" can be
programmed in reverse characters.

After 10 sums have been attempted, the user is told "Well done", and his
score out of 10 is printed. This display remains on the screen for several
seconds after which the program restarts automatically.

The Pause function has not been used within the main body of the program
where delays were required since it tends to cause disturbances to the
display. Instead, the single-line

    X = RND**RND**RND

is used. A For-Next loop could have been used, but it would have required
two lines for each delay. The program will run on a 1K ZX-81 and should
provide a good deal of educational entertainment for the younger members of
the family.
