A programmer is writing an algorithm to output and sum the quarterly performance figures for four regional branches of a retail business during three quarters of a year. Each branch has 3 sales figures recorded, making 12 historical records in total.
The algorithm in Figure 1 contains a logical error and does not process all of the sales figures.
Figure 1
1 regions ← ['North', 'East', 'South', 'West']
2 sales ← [120, 150, 130, 90, 110, 95, 200, 210, 205, 80, 85, 90]
3 totalSales ← 0
4 FOR i ← 0 TO 3
5 area ← regions[i]
6 OUTPUT 'Region: ', area
7 FOR j ← 0 TO 1
8 OUTPUT 'Quarterly Record: ', j + 1
9 val ← sales[i * 3 + j]
10 OUTPUT val
11 totalSales ← totalSales + val
12 ENDFOR
13 ENDFOR
How could the error in the algorithm in Figure 1 be corrected so that all sales figures are processed?
Change line number 3 to: totalSales ← -1
Change line number 4 to: FOR i ← 0 TO 4
Change line number 7 to: FOR j ← 0 TO 2
Change line number 9 to: val ← sales[j * 4 + i]
298 exam-style questions on AQA GCSE Computer Science Programming concepts. Each one has a worked solution and a mark scheme showing where the marks go.