Question 15

AQA Computer Science Specimen Paper 1C (8525/1C)GCSE4 marks

On the specification

3.2 Programming
Question text

15 A program has been written in VB.Net 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 Dim odd As Integer = 1 Dim number As Integer Console.Write("Enter an integer: ") number = Console.ReadLine() While odd <> number Console.WriteLine(odd) odd = odd + 2 End While 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 VB.Net 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]