Question 6

OCR Computer Science June 2022 Algorithms and problem solving (H046-02)AS7 marks

On the specification

(a)
2.2 Problem solving and programming
(b)
2.2 Problem solving and programming
(c)
1.4 Data types, data structures and algorithms
Question text

6 Kylie buys used games consoles and then sells them to make a profit. She sells her products in multiples of £5 such as £30, £55 and £95. Kylie only accepts £50, £20, £10 and £5 notes from her customers. Kylie has written an algorithm which will calculate the amount of change needed by stating how many £20, £10 and £5 notes are needed. The program should output the minimum number of notes required. For example if £35 change is required then it should output 1 x £20 and 1 x £10 and 1 x £5. 1 total = input("Enter total price of goods") 2 paid = input("Enter amount paid”) 3 global change = paid – total 4 calculateChange() 5 6 procedure calculateChange() 7 twenty = 0 8 ten = 0 9 five = 0 10 while change >= 20 //Calculates number of £20 notes needed 11 twenty = twenty + 1 12 change = change – 20 13 endwhile 14 while change >= 10 //Calculates number of £10 notes needed 15 ten = ten + 1 16 change = change – 10 17 endwhile 18 while change >= 5 //Calculates number of £5 notes needed 19 five = five + 1 20 change = change – 5 21 endwhile 22 print("The amount of change you need is £" + str(change)) 23 print("Total £20 Notes:" + str(twenty)) 24 print("Total £10 Notes:" + str(ten)) 25 print("Total £5 Notes:" + str(five)) 26 endprocedure (a) Describe how calculateChange() on line 04 is used differently to calculateChange() on line 06. [2] (b) When line 22 is run, it will always print: The amount of change you need is £0 Explain why this error occurs when line 22 is run. [2] (c) Explain why Kylie has used str on lines 22 to 25 in her algorithm. [3]