Keep going, and add another line at 60:
5 CLS
1 0 I N P U T " W H A T I S Y O U R S A L A R Y " ; S A L A R Y
2 0 I F < 1 0 0 0 0 T H E N G O T 0 1 0 0 0 0 T H E N G O T 0 3 0 E L S E 40
3 0 P R I N T " A S K F O R A P A Y R I S E " : E N D
4 0 P R I N T " A S K F O R A B I G G E R C A R "
50 I F S A L A R Y > 3 0 0 0 0 T H E N P R I N T
" a n d g e t a g o o d a c c o u n t a n t "
6 0 I F S A L A R Y > 2 5 0 0 0 THEN PRINT
“. . . .lend me a fiver"
run
Note the relational operators (> and <) act as delimiters to mark the boundaries of the number, and
that you do not need to put a space before or after them - if you do, the space will be ignored by
BASIC. If you answer 26000 when you run this program, then you will see that BASIC passes
through line 50 as if it was not there, and gets trapped by the operation in line 60.
At this point, construct a program of your own using the topics covered so far. Note the way in which
this program has been ‘grown’ - most programs evolve in this way, which introduces perhaps the
most important concept in programming that utilises the ideal organising ability of BASIC....
4.6 Evolution
:
the origin of programs
The way in which BASIC allows you to build programs as you go along is its most convenient
feature. Purists will argue that this convenience leads to sloppy and ‘unstructured’ programming
techniques with programs being tacked together as ideas occur; realists may consider it’s the best
way to retain the interest of the student, who has the means of checking progress in easy stages.
Take our example program again, and now add line 70 which loops the program back to the
beginning, after pausing long enough for you to read the screen response:
5 CLS
1 0 I N P U T " " W H A T I S Y O U R S A L A R Y " ; S A L A R Y
2 0 I F S A L A R Y < 1 0 0 0 0 T H E N G O T 0 3 0 E L S E E L S E 40
3 0 P R I N T " A S K F O R A P A Y R I S E " : E N D
4 0 P R I N T " A S K F O R A B I G G E R C A R "
50 IF S A L A R Y > 3 0 0 0 0 T H E N P R I N T
" a n d g e t a g o o d a c c o u n t a n t "
6 0 I F S A L A R Y > 2 5 0 0 0 T H E N P R I N T
“ … . a n d l e n d m e a f i v e r "
7 0 f o r n = 1 t o 9 0 0 : n e x t n : g o t o 5
run
Note that the new line, and other lines that have been added, have been entered in lower case to
remind you that AMSTRAD BASIC understands the difference between a variable name, and
keyword. Press
[ESC]
twice to break from this program, then LIST the program and see how the
computer converts the keywords to UPPER CASE letters, but leaves the variable n in lower case.
Содержание CPC464
Страница 1: ......
Страница 32: ...or you can type 3e1 1e1 ENTER 300 2 3000x1000 Type 3e3 1e3 ENTER 3000000 3 3000x0 001 Type 3e3 1e 3 ENTER 3 ...
Страница 102: ...PRINT 10 AND 12 Results in 8 PRINT 10 AND 1000 Results in 8 again ...
Страница 118: ...TO DO DRAW THIS PAGE ...
Страница 219: ...actual value may be made to vary during the execution of a program ...
Страница 240: ...Text and WINDOW planner Mode 2 80 Columns ...
Страница 241: ......
Страница 245: ...Sound envelope Music planner sheet ...