EasyManua.ls Logo

Commodore 128D - Sample Program

Commodore 128D
427 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
u
Sample
Program
Now
that
you
know
how
to
use
the
FOR-NEXT
loop
and
the
INPUT
|
I
command,
clear
the
computer's
memory
by
typing
NEW
'—'
T
then
type
the
following
program:
10T =
0
20
INPUT"HOW
MANY
NUMBERS";N
30FORJ
=
1TON
40
INPUT'PLEASE
ENTER
A
NUMBER
";X
50T
=
T
+ X
60
NEXT
70A
=
T/N
LJ
80
PRINT
90
?
"YOU
HAVE";N"NUMBERS
TOTALING'r;T
100
?
"AVERAGE
=
";A
ij
110
END
This
program
lets
you
tell
the
computer
how
many
numbers
you
want
i i
to
average.
You
can
change
the
numbers
every
time
you
run
the
[—^
program
without having
to
change
the
program
itself.
Let's
see
what
the
program
does,
line
by
line:
v.
)
Line
10
assigns
a
value
of
0
to
T
(which
will
be
the
running
total
of
the
numbers).
j
j
Line
20
lets
you
determine
how
many
numbers
to
average,
stored
in
variable
N.
Line
30
tells
the
computer
to
execute
a
loop
N
times.
Line
40
lets
you
type
in
the
actual
numbers
to
be
averaged.
i
j
Line
50
adds each
number
to
the
running
total!
Line
60
tells
the
computer
to
go
back
to
line
30,
increment
the
\
j
counter
(J)
and
start
the loop
again.
(—'
Line
70
divides
the
total
by
the
amount
of
numbers
you
typed
(N)
after
the
loop
has
been
executed
N
times.
j
j
Line
80
prints
a
blank
line
on
the
screen.
Line
90
prints
the
message
that
gives
you
the
amount
of
num-
|
|
bers
and
their
total.
Line
100
prints
the
average
of
the
numbers.
t
i
Line
110
tells
the
computer
that
your
program
is
finished.
u
58
USING
C128
MODE—Advanced
BASIC
Programming
'—
u

Table of Contents

Other manuals for Commodore 128D

Related product manuals