ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions
2 marks · Standard algorithms
Craig has been asked to write an algorithm that will search for a target ID from a list of fifty receipts. Each receipt has a unique receipt ID. Part of the algorithm is shown below. Line 1 SET found TO false Line 2 SET counter TO −1 Line 3 RECEIVE target_id FROM (INTEGER) BARCODEREADER Line 4 REPEAT Line 5 SET counter TO counter + 1 Line 6 IF receipt_id [counter] = target_id THEN Line 7 SET found TO true Line 8 END IF Line 9 UNTIL Using pseudocode, or a language with which you are familiar, complete line 9 of the algorithm shown above.
1 mark for correct simple condition found = true/counter = 49 2 marks for correct complex condition found = true OR counter = 49 Accept end of list/accept index of 50 eg OR end of list This question is not assessing indexing from zero.
Previous question: Higher Computing Science 2015 Question 6 (CfE)
Next question: Higher Computing Science 2015 Question 8 (CfE)