BASIC12.WPS

BASIC LANGUAGE PROGRAMMING

USING TRAILING DATA TRIGGERS

IN READ/DATA STATEMENTS

Programs are often terminated by using specific data.

If, for example, you had a program which reads the name and age of a group of students, you could terminate the program by using a negative number for the age!

This technique allows programmers to add or subtract students from the database without having to re-write the program. Only the data statements must be changed.

Here is an example:

REM THIS PROGRAM PRINTS NAMES AND AGES UNTIL A NEGATIVE

REM AGE IS FED IN AS DATA

DO WHILE AGE >= 0

READ NAME$, AGE

PRINT NAME$, AGE

LOOP

END

DATA BILL, 15

DATA JOE, 17

DATA GIL, 12

DATA XXX, -3

 

Assignment - Write programs to do the following:

1) The coach of a hockey team is trying to keep track

of how the players are performing during the season.

He has developed a BASIC program which uses READ/DATA

statements to update the persons total points after each

game. Write a program which will READ one players name,

assists and goals and generate a season total points for

that player. The program will keep reading data until

a negative number is fed into the goals data statement.

Once the program reads a negative number in the goals

category it will print out the players name and total

points for the season.

2) Re-do the program in 1) so that the program can

track 3 players simultaneously and give a points total

for each of the three when fed a negative number in the

goals category.

Copyright - Barry Boyle (bboyle@kawartha.net)