Radio Shack TRS-80 Model 100 Basic Manual page 84

Basic language lab
Hide thumbs Also See for TRS-80 Model 100:
Table of Contents

Advertisement

Experiment #6 Changing Line Numbers
Delete the previous program from working memory with the NEW command.
The following program allows an arbitrary list of numbers to be entered from the
keyboard. When a zero in entered, the average of the non-zero numbers is computed
and displayed. (At least that is what the program should do.)
Type the program exactly as it is listed:
10 INPUT "NUMBER"; N
20 CT
=
CT + 1
30 AI)
=
Al,l
+
N
40 IF N=0 THEN GDTO 80
50 GOTO 10
80 PRINT "At,lERAGE IS"; AI)/CT
The program accumulates the sum of the numbers in the variable AV. The variable
CT is a counter that records the number of values entered.
If
the number entered is
@,
then the average is printed in line 6@.
Here is an example of the execution of the program:
NUMr.ER?
' i -
NUMBt::rp
~2
NUMBE:F~?
el
AVE H/7iGE IS :2
Ok
Obviously, the program is not working correctly. The average of the two numbers is
3, not 2. The reason for the inaccuracy is that the number 0 was counted by the
variable CT.
The program can be correcled by inlerchanging lines 20 and 40. In this way, the
check for a zero value for N is done before the number N is counted. One way of
changing the order of the statements is to retype the two lines. However, an easier
method is to use the Editor to change the line numbers.
Use the command
ED I T
(ENTER)
to enter the Edit Mode.
78

Advertisement

Table of Contents
loading

Table of Contents