Identifying Errors (Cambridge (CIE) IGCSE Computer Science)

Topic Questions

20 mins5 questions
13 marks

An algorithm allows a user to input their password and checks that there are at least eight characters in the password. Then, the user is asked to re-input the password to check that both inputs are the same. The user is allowed three attempts at inputting a password of the correct length and a matching pair of passwords. The pre-defined function LEN(X) returns the number of characters in the string, X

01 Attempt ← 0
02 REPEAT
03 PassCheck ← TRUE
04 OUTPUT "Please enter your password "
05 INPUT Password
06 IF LEN(Password) < 8
07 THEN
08 PassCheck ← TRUE
09 ELSE
10 OUTPUT "Please re-enter your password "
11 INPUT Password2
12 IF Password <> Password
13 THEN
14 PassCheck ← FALSE
15 ENDIF
16 ENDIF
17 Attempt ← Attempt + 1
18 UNTIL PassCheck OR Attempt <> 3
19 IF PassCheck
20 THEN
21 OUTPUT "Password success"
22 ELSE
23 OUTPUT "Password fail"
24 ENDIF

Identify the three errors in the pseudocode and suggest a correction to remove each error.

Did this page help you?

24 marks

An algorithm has been written in pseudocode to allow some numbers to be input. All the positive numbers that are input are totalled and this total is output at the end. An input of 0 stops the algorithm.

01 Exit ← 1
02 WHILE Exit <> 0 DO
03 INPUT Number
04 IF Number < 0
05 THEN
06 Total ← Total + Number
07 ELSE
08 IF Number = 0
09 THEN
10 Exit ← 1
11 ENDIF
12 ENDIF
13 ENDIF
14 OUTPUT "The total value of your numbers is ", Number

Identify the four errors in the pseudocode and suggest a correction for each error.

Did this page help you?

33 marks

An algorithm has been written in pseudocode to calculate a check digit for a four-digit number. The algorithm then outputs the five-digit number including the check digit. The algorithm stops when –1 is input as the fourth digit.

01 Flag FALSE
02 REPEAT
03 Total 0
04 FOR Counter 1 TO 4
05 OUTPUT "Enter a digit ", Counter
06 INPUT Number[Counter]
07 Total Total + Number * Counter
08 IF Number[Counter] = 0
09 THEN
10 Flag TRUE
11 ENDIF
12 NEXT Counter
13 IF NOT Flag
14 THEN
15 Number[5] MOD(Total, 10)
16 FOR Counter 0 TO 5
17 OUTPUT Number[Counter]
18 NEXT
19 ENDIF
20 UNTIL Flag

Identify the three errors in the pseudocode and suggest a correction for each error.

Did this page help you?

1a
Sme Calculator
4 marks

An algorithm has been written in pseudocode to input some numbers. It only outputs any numbers that are greater than or equal to 100. The number 999 is not output and stops the algorithm.

INPUT Number
WHILE Numbers <> 999 DO
   IF Number > 100
      THEN
         OUTPUT Number
   ENDIF
ENDWHILE
OUTPUT Number

Identify the four errors in the pseudocode and suggest corrections.

1b
Sme Calculator
2 marks

Write a pseudocode statement to change the corrected algorithm to output all numbers between 100 and 200 inclusive.

You do not need to rewrite the whole algorithm

Did this page help you?

24 marks

This section of program code asks for 80 numbers between 100 and 1000 inclusive to be entered. The pseudocode checks that the numbers are in the correct range and then stores the valid numbers in an array. It counts how many of the numbers are larger than 500 and then outputs the result when finished.

01 Count ← 0
02 FOR Index ← 1 TO 80
03 INPUT "Enter a number between 100 and 1000 ", Number
04 WHILE Number <= 99 AND Number >= 1001
05 INPUT "This is incorrect, please try again", Number
06 ENDWHILE
07 Num[80] ← Number
08 IF Number > 500 THEN Count ← Count + 1 ENDIF
09 UNTIL Index = 80
10 PRINT Index
11 PRINT "numbers were larger than 500"

There are four lines of code that contain errors.

State the line number for each error and write the correct code for that line.

Did this page help you?