The program shown in Figure 1 is designed to output 4 randomly selected alkali metal names from an array, but it contains a logic error.
Identify the line number that contains the logic error, and write the corrected line of code.
Your corrected line must be written in C#.
Figure 1
1 string[] elements = { "Lithium", "Sodium", "Potassium", "Rubidium", "Cesium", "Francium" };
2 int displayed = 0;
3 Random rand = new Random();
4 while (displayed < 4) {
5 displayed = displayed + 1;
6 int randIdx = rand.Next(0, 6);
7 Console.WriteLine(elements[displayed]);
8 }
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.