Given an array temps of Doubles, containing temperature data, compute the average temperature.

Given an array temps of Doubles, containing temperature data, compute the average temperature.

LANGUAGE: Visual Basic

CHALLENGE:

Given an array temps of Doubles, containing temperature data, compute the average temperature.  Store the average in a variable called avgTemp.  Besides temps and avgTemp, you may use only two other variables — an Integer variable k and a Double variable named total, which have been declared.

SOLUTION:

k = 0
total = 0
Do
    total += temps(k)
    k += 1
Loop Until (k = temps.length)
avgTemp = total / k

Add comment