Line
10
will be changed
so
that the name
of
the salesman can be entered along with
the sales amount.
10
INPUT
"NAME,
SALES"; N$,
ST
The name will be placed in the string variable
N$
and the sales amount in the numeric
variable ST. Line 20 will correctly calculate the commission, but line 40 must be
altered so that the name
is
printed. Change line 40
to:
40
PRINT
"COMMISSION
FOR
";
N$;"
IS
";
If
the name entered is SMITH, then line 40 will print
COMMISSION
FOR
SMITH
IS
and
line 50 will print the amount
of
the commission after the word IS.
Here is a listing of the program after the changes have been made:
10
INPUT
"NAME,
SALES"; N$,
ST
20
IF
ST
(=
2000
THEN
CM
=
.15
*
ST
ELSE
CM
=
.20
*
ST
40 PRINT
"COMMISSION
FOR
"i
N$i"
IS
";
45
A$
=
"**$###,###.##"
50
PRINTUSING ASi
CM
If this program were executed, it would compute the commission
of
a single salesman
and execution would terminate.
If
the program
is
to
compute more than one sales
commission, it must branch back
to
line
10.
This can be accomplished with the use
of
a
GOTO
statement after line 50. Type in a new line:
G0
GOTO
10
Now the program
is
complete:
10
INPUT
"NAME,
SALES" i NS,
ST
20
IF
ST
<=
2000
THEN
CM
=
.15
*
ST
ELSE
CM
=
.20
*
ST
40 PRINT
"COMMISSION
FOR"
iNS;"
IS
";
45
A$
=
"**$###,###.##"
50
PRINTUSING A$i
CM
G0
GOTO
10
This program illustrates a concept in programming called
"looping."
This means that
a block of statements are repeated several or perhaps many times
in
a program. In the
program above, the entire program is repeated, each time with a different salesman
and sales total.
It
should be noted that the program is an "infinite loop," which
means
it
will not terminate and must be manually terminated by pressing
(BREAK).
Try running the program and entering several names and sales amounts. Be sure to
press
~
when you wish
to
terminate execution.
53