In my entrance examination problems must be written in pseudocode or as flow charts. I tried to write pseudocode that scans 24 temperature readings and prints MIN, MAX, and AVG, but I didn't get the AVG in:
max = 0 min = 0 set up array of a[24] loop start if a[x] > max
max = a[x]
else if a[x] < min
min = a[x]
print Max temp: print Min temp:
How would I construct a clear pseudocode of this program?
Smaller statements tend to be better. I'd rewrite your provided snippet as:
count = 24
temperatures is an array of count elements
max = -9999
min = 9999
total = 0
for each value in temperatures
total = total + value
if value > max
max = value
else if value < min
min = value
print "Minimum: " min
print "Maximum: " max
print "Average: " total / count
It's almost real python code. The following is real python code:
count = 24
temperatures = [3 * x for x in range(count)]
max = -9999
min = 9999
total = 0.0
for value in temperatures:
total = total + value
if value > max:
max = value
if value < min:
min = value
print("Minimum: ", min)
print("Maximum: ", max)
print("Average: ", total / count)