How the simple interest program works:
Line
18
assigns the value
of
10000 to the variable P. This is called an assignment
statement.
The letter P is called a numeric variable because numerical values can
be
assigned to it. Note that the principal, $10,000, is written without the dollar sign ($)
or
comma (,). In general, numeric constants should
be
written without
commas
or
dollar signs
in
BASIC.
Line
28
assigns the value
of
.18
to the variable R. This is the decimal equivalent
of
the 18% interest rate. The conversion to decimal form is necessary because BASIC
does not allow numeric constants to be written with a percent
(%) symbol.
Line
38 assigns the value
of
10 to the variable T. This is the length
of
time (10 years)
allowed to repay the loan.
Line
48
computes the
sum
of
principal and interest and assigns it to the variable S.
Note that the expression,
P *
(1
+ R *
T),
looks very much like the formula previously seen for calculating the sum.
The
symbol
"*,,
is used to denote multiplication and, as usual, + denotes addition.
Line
58
prints
an
explanatory message and the value
of
S.
The variables
P,
R,
T and S are all valid examples
of
numeric variables. A numeric
variable can be
a) any letter
b) any two letters
or
c) a letter followed
by
a number.
For example, the following are all valid numeric variables:
A
AA
B2
CQ
Y9
But the following are not valid numeric variables:
IS
$5
A?
"
*
I
The ftrst four lines
of
the program are assignment statements. In general, an
assignment statement follows the form:
variable = expression
where "variable" is any valid numeric variable and "expression" is any valid
numeric expression.
The
right hand side can
be
a constant. The value
of
the
expression is assigned to the variable.
The
arithmetic operators in BASIC are:
+ addition
subtraction
multiplication
division
exponentiation
32