ERRORS

ERRORS

ERRORS

An error is a condition which causes a computer to fail to produce the expected results.

Errors occur at all stages of developing and implementing a program and a large proportion of computing effort is aimed at detecting or avoiding them.

The main causes of errors are:

1 Faulty system design.

2 Hardware failure.

3 Errors in the program.

4 Errors in the data.

5 Inaccurate calculation.

Program Errors

An error in a program is called a bug. Bugs may be one or more of the following.

SYNTAX ERRORS

A syntax error occurs when a language is not used correctly. A compiler or interpreter will not be able to translate statements with syntax errors because they do not make sense.

Syntax errors usually occur because:

1 The programmer has misunderstood the rules of the language; or

2 A transcription error has been made. A transcription error is a mistake made in writing or keying.

Examples of syntax errors in BASIC

1 300 LET A=2(X+3)

This should read ‘300 LET A=2*(X+3)’. The programmer probably did not realize that an asterisk was needed.

2 100 IF A$="***" TEN 200

This should read ‘100 IF A$="***" THEN 200’. This was probably a transcription error.

LOGICAL ERRORS

A logical error occurs when the program designer or the programmer makes a mistake in working out the sequence of instructions required to produce a particular result.

Exam pies of logical errors

1 The following BASIC program module is intended to print ‘INCORRECT MONTH’ whenever the value of MONTH is not between 1 and 12, inclusive.

100 REM ******* MONTH CHECK *******

110 IF MONTH>12 THEN 200

120 IF MONTH<1 THEN 200

200 PRINT "INCORRECT MONTH"

In fact there is a logical error because it will still execute line 200 and print ‘INCORRECT MONTH’ if MONTH does lie between 1 and 12. A GOTO statement is required at tine 130, so that line 200 is not executed if the month is acceptable.

2 The following module is intended to input a set of names into the array SNAME$:

200 REM ***** INPUT SURNAMES *******

210 PRINT "TYPE EACH SURNAME. THEN PRESS ‘RETURN’" 220 PRINT "AFTER THE LAST NAME. ENTER ·

230 LET COUNT=0

240 LETCOUNT=COUNT+l

250 INPUT SNAME$(COUNT)

260 IF SNAME$(COUNT) = " *** " THEN 500

270 GOTO 230

When this module has been run SNAME$(1) will have the value "***". All the other elements of SNAME$ will be blank and no names will have been stored. This is because line 270 says ‘GOTO 230’, which sets COUNT=0 every time round the loop. Line 270 should read ‘GOTO 240’, so that COUNT is incremented.

Leave a comment

Your email address will not be published. Required fields are marked *