4
0/2

A program simulates a smart thermostat's automatic calibration routine where a target temperature is randomly selected.

The program must generate a random integer between -5 and 35 (including both -5 and 35 Celsius). This will represent the target test temperature.

Write the VB.NET code that should be used on line 3 of the program below to:

  • generate a random integer between -5 and 35 inclusive
  • assign this number to the appropriate variable from the program.

You must use rng.Next(a, b) in your VB.NET code.

Note: rng.Next(a, b) generates a random integer starting at a up to, but not including, b.

1      Dim rng As New Random()
2      Dim targetTemp As Integer
3
4      Console.WriteLine("Enter a test temperature in Celsius (-5 to 35):")
5      Dim testTemp As Integer = Console.ReadLine()
6      While testTemp < -5 Or testTemp > 35
7          Console.WriteLine("Out of system calibration range.")
8          testTemp = Console.ReadLine()
9      End While
10     Console.WriteLine("Calibration point recorded.")
11     If targetTemp = testTemp Then
12         Console.WriteLine("Target matched exactly during test!")
13     End If
[2]

Random number generation in a programming language Questions

Practise AQA GCSE Computer Science Random number generation in a programming language with exam-style questions for GCSE Computer Science. 8 questions, matched to the AQA GCSE Computer Science (8525) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.

PreviousNext

Random number generation in a programming language Questions

  1. GCSE
  2. /Computer Science
  3. /Random number generation in a programming language