Average until zero
Reads numbers with USERINPUT in a WHILE loop until the user enters 0, then outputs the average.
Input and outputLoops
# Average of the numbers entered (0 to stop)
total ← 0
count ← 0
OUTPUT 'Enter a number (0 to stop)'
number ← USERINPUT
WHILE number ≠ 0
total ← total + number
count ← count + 1
number ← USERINPUT
ENDWHILE
IF count > 0 THEN
OUTPUT 'Average: ', total / count
ELSE
OUTPUT 'No numbers entered'
ENDIF- Inputs
- 8, 4, 6, 0
- Output
Enter a number (0 to stop) Average: 6