Marcus wants to program a temperature calibration simulator for a smart thermostat.
The program will generate a random target temperature between 15 and 30 inclusive.
The user must guess the target temperature to calibrate the sensor.
This pseudocode contains the logic required to run the simulator.
1 # Initialise variables
2 SET attempts TO 1
3 SET target TO RANDOM(15) + 15 # i.e. a random integer 15 to 30 inclusive
4 SET guess TO 0
5
6 # Print prompt and take guess from user
7 SEND "Enter a target temperature from 15 to 30: " TO DISPLAY
8 RECEIVE guess FROM (INTEGER) KEYBOARD
9
10 # Create while loop to check guess
11 WHILE guess <> target DO
12 SET attempts TO attempts + 1
13 IF guess > target THEN
14 SEND (guess & " is too high. Try cooling it down.") TO DISPLAY
15 ELSE
16 SEND (guess & " is too low. Try heating it up.") TO DISPLAY
17 END IF
18 SEND "Adjust temperature: " TO DISPLAY
19 RECEIVE guess FROM (INTEGER) KEYBOARD
20 END WHILE
21
22 # Report correct temperature and attempts
23 SEND ("Correct! Target of " & guess & " degrees reached in " & attempts & " attempts.") TO DISPLAY
Write a program to implement the logic in the pseudocode.
Open Q02a in the code editor.
You must use the structure given in Q02a to write the program.
Do not add any further functionality.
Save your code as Q02aFINISHED with the correct file extension for your programming language.