Writing A Simple Program - AMSTRAD cpc 6128 User Instruction

Integrated computer/disc system
Hide thumbs Also See for cpc 6128:
Table of Contents

Advertisement

Fortunately, BASIC is a very forgiving language and will often help you by
producing error messages on the screen when you go wrong. BASIC also allows you to
have 'afterthoughts', and new lines of program can be sandwiched in between the
existing lines with a minimum offuss.
Writing
a simple program
OK let's get going. We'll write a program to keep a record of our friends' names and
telephone numbers. We'll call the program 'Telephone book'. Now let's apply the
above rules: 'What should the program do?' and 'How should the results be
presented?'
Well, the program should let you enter up to say, 100 names and 'phone numbers for
storage. When you want a number, you should be able to type in the name and get
back the number. In addition, if you're not sure how one of the names was originally
entered, you should be able to display a complete list of all the information on the
screen. Notice by the way, that we're automatically starting to consider the question
of how the results ofthe program are to be presented.
Right, let's put finger to keyboard! We'll start off with the title at the beginning:
10 REM teLephone book
You don't have to put a title in a program, but when you start to accumulate quite a
few programs, it helps to be able to know at a glance which is which.
Next, we know that we want to be able to IN PUT (put in) a string of characters
(somebody's name) into a variable; we'll call that variable N A M E $. The same applies
to the telephone number, and we'll call that variable
T E L
$.
Remember those example programs from the Foundation course? They used the
IN PUT command for you to enter the value ofthe variable, so if we type in:
20 INPUT "enter the name";NAME$
30
INPUT "enter the teLephone number";TEL$
run
You could enter the name, for example: Joe. You could then enter the 'phone number,
for example: 0277 230222
The program has stored the information, but hasn't produced any printed results on
the screen. A section of program is therefore needed to retrieve the information, then
display it. To get the values of N A M E $ and T E L $ at the moment, we'd use commands
like:
PRINT NAME$ ....
and ....
PRINT TEL$
Chapter 2 Page 2
Beyond Foundations

Advertisement

Table of Contents
loading

Table of Contents

Save PDF