Error Worksheet
Error Worksheet
Error Worksheet
Class: IX
Q.1 The following algorithm inputs 20 numbers and outputs how many numbers were positive
(> 0) and how many numbers were negative (< 0).
1 negative = 1
2 positive = 1
3 for count = 1 to 20 do
4 input number
5 if number < 0 then negative = negative + 1
6 if number > 0 then positive = positive + 1
7 count = count + 1
8 print negative, positive
9 next count
There are three different errors in this algorithm.
Locate each error and give the reason why you think it is an error.
Error 1
Reason 1.
Error 2
Reason 2
Error 3
Reason 3[6]
Q.2 A golf course charges $10 for each game of two people. Each additional person incurs a
further charge of $2 per game. If they book two or more games in advance, they get a 10%
discount on the total charge.
The following program has been written in pseudocode to calculate the charges for a game.
1 extracost = 0
2 input numberpeople, numbergames
3 charge = 10 * numbergames
4 extrapeople = numberpeople 2
5 if numberpeople < 2 then extracost = 2 * extrapeople * numbergames
6 charge = extracost
Q.4 A piece of pseudocode was written to input 1000 positive numbers and then output the
Name three different types of test data. Using month from the pseudocode above, give
an example of each type of test data.
test data type 1..
example
test data type 2..
example
test data type 3..
example. [6]
Q.6 The following section of pseudocode inputs rainfall (in cm) for 500 days and outputs the
average rainfall and the highest rainfall input.
Locate the 3 errors and suggest a corrected piece of code.
1 highest = 1000
2 days = 1
3 while days > 0
4 input rainfall
5 if rainfall > highest then highest = rainfall
6 endif
7 total = total + rainfall
8 days = days + 1
9 average = total/500
10 endwhile
11 print average, highest
Error 1
Correction
Error 2
Correction
Error 3
Correction[6]