EasyManua.ls Logo

Commodore 128D - Using Parentheses to Define the Order of Operations; Constants, Variables and Strings; Constants

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...
Constants,
Variables
and
Strings
Exponentiation,
or
raising
a
number
to
a
power,
takes
precedence
over
the
other
four
mathematical
operations.
For
example,
if
you
type:
PRINT
16/4T2
RETUKNr
the
Commodore
128
responds
with
a
1
because
it
squares
the
4
before
it
divides
16.
Using
Parentheses
to
Define
the
Order
off
Operations
You can
tell
the
Commodore
128
which
mathematical
operation
you
want
performed
first
by
enclosing
that
operation
in
parentheses
in
the
PRINT
command.
For
instance,
in
the
first
example
above,
if
you
want
to
tell
the
computer
to
add
before
dividing,
type:
PRINT
(4
+
6)/2
nCTUIUil
This
gives
you
the desired
answer,
5.
If
you
want
the
computer
to
divide
before
squaring
in
the
second
example,
type:
PRINT
(16/4)T2
RETURN
Now
you
have
the
expected
answer,
16.
If
you
don't
use
parentheses,
the
computer
performs
the
calcula
tions
according
to
the
above
rules.
When
all
operations
in
a
calcula
tion
have
equal
precedence,
they
are
performed
from
left
to
right.
For
example,
type:
PRINT
4*5/10*6
HLIUHN
Since
the
operations
in
this
example
are
performed
in
order
from
left
to
right,
the
result
is
12(4*5
=
20....
20/10
=
2...
2*6=
12).
If
you
want
to
divide
4*5
by
10*6
you
type:
PRINT(4*5)/(10*6)
ULIUHII
The
answer
is
now
.333333333.
Constants
Constants
are
numeric
values
that
are
permanent:
that
is,
they
do
not
change
in
value
over
the
course
of
an
equation
or
program.
For
example,
the
number
3
is
a
constant,
as
is
any
number.
This
state
ment
illustrates
how
your
computer
uses
constants:
10
PRINT
3
No
matter
how
many
times
you
execute
this
line,
the
answer
will
always
be
3.
38
USING
C128
MODE—Getting
Started
in
BASIC

Table of Contents

Other manuals for Commodore 128D

Related product manuals