Question 15
AQA Computer Science Specimen Paper 1A (8525/1A)GCSE4 marks
On the specification
- 3.2 Programming
Question text
15 A program has been written in C# to display all the odd integers between 1 and the largest odd number smaller than an integer entered by the user. The program is shown in Figure 6. Figure 6 int odd = 1; int number; Console.Write("Enter an integer: "); number = Convert.ToInt32(Console.ReadLine()); while (odd != Number) { Console.WriteLine(odd); odd = odd + 2; } Console.WriteLine("Finished!"); The program works correctly if the integer entered by the user is an odd, positive integer. For example, if 7 is entered the program correctly displays the values 1, 3 and 5 The program does not work correctly if an odd integer less than 1 is entered by the user. For example, when -7 is entered the program should display the values 1, -1, -3 and -5 but it doesn’t do this. Using C# only, change the program code inside the while loop so that it will work correctly for any odd integer entered by the user. [4 marks]