boat

Pseudocode

FOR...TO...NEXT

An environmental scientist records the temperature every 30 minutes everyday for 4 hours using a digital thermometer ie 8 times.

The data is input into a computer system.

If any data is greater than 28oC, then it is counted.

The computer program will output the average temperature and the number of times a temperature greater than 28oC was recorded.

Here is an algorithm, represented as pseudocode, to solve this problem.

Pseudocode

count ← 0

total ← 0

FOR i ← 0 TO 8

PRINT "Enter a temperature as a real number:"

temp ← USERINPUT

total ← total + temp

IF temp > 28.0 THEN

count = count + 1

ENDIF

NEXT i

average ← total/8

PRINT "The average temperature is ", average, " degrees Celcius"

PRINT count, "temperatures of more than 28.0 were recorded."

Use this pseudocode to write a working solution using program code. There is 1 mistake in it. Find the mistake and fix it.

Notice the structure of a for loop in pseudocode. It is quite different from Python or Java or Ruby:

FOR i ← 0 TO 8

...

NEXT i