EasyManuals Logo

Radio Shack TRS-80 Model 100 User Manual

Radio Shack TRS-80 Model 100
210 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #103 background imageLoading...
Page #103 background image
Experiment
#4
Four Seasons
To compute the average ratio
to
trend for the second quarter, you could simply change
the start value
of
X to 2 in line 140:
140 FOR X
= 2 TO N STEP 4
A start value of 3 would compute the third quarter ratio and a start value of 4 would
compute the fourth quarter ratio. The message "QUARTER I RATIO
IS"
would still
appear for every quarter since nothing has been done to line 170. Rather than
manually change line
140
for each quarter, however, you could modify the program to
do
this for you. Enter the following changes to the program:
130
FOR
Q
:::
1
TO
4
135
R
=
0
140
FOR
X
=
Q
TO
N STEP 4
170
PRINT
"QUARTERljQj"
RATIO
IS"jR/6
180
NEXT
Q
Run this program
to
confirm that it now prints the average ratio to trend for all four
quarters:
1'+8.22463768116
QUARTER
1 RATIO
QUARTER
2 RATIO
QUARTER
3 RATIO
QUARTER
4 RATIO
Ok
X
IS
+
8.4086956521739
IS
.9230187061999
IS
1.0761822655641
IS
.86424468709917
IS
1.1358281261464
Lines 138
and
198 define a program loop which repeats for each of the four quarters.
Notice that this loop contains within it another loop from line
140
to
line 160. This
is
an example of a programming concept known as
"nested
loops."
It
simply means
that there is a loop
of
statements within a loop of statements.
The inner FOR / NEXT loop must be completely contained within the outside loop,
no
overlap is allowed. In this experiment, the inner loop, lines 140 to 160, compute the
average ratio
to
trend for a specified quarter Q, and the outer loop, lines 130 to 190,
which repeats for each quarter with the index variable Q
= 1, 2, 3 and 4.
Line 135 resets the ratio sum variable R to zero before starting the calculation for
each quarter. This is now necessary to avoid starting with the sum remaining from the
previous quarter.
Line
178 was changed
to
print the quarter Q along with the average ratio to trend R/6.
97

Other manuals for Radio Shack TRS-80 Model 100

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Radio Shack TRS-80 Model 100 and is the answer not in the manual?

Radio Shack TRS-80 Model 100 Specifications

General IconGeneral
BrandRadio Shack
ModelTRS-80 Model 100
CategoryDesktop
LanguageEnglish

Related product manuals