PROGRAM average2
!
! Author:  Br. David Carlson
!
! Date:  February 7, 2000
!
! Revised:  May 2, 2004
!
! This program prompts the user to enter floating point numbers, with 0
! used to indicate the end of data.  The average of the numbers (not
! including the 0) is calculated and printed.

IMPLICIT NONE

REAL::sum, item, average
INTEGER::count

count = 0
sum = 0.0

WRITE (*, *) 'Enter a float (or 0 to quit)'
READ (*, *) item

DO WHILE (item /= 0.0)
   sum = sum + item
   count = count + 1
   WRITE (*, *) 'Enter another float (or 0 to quit)'
   READ (*, *) item
END DO

IF (count > 0) THEN
   average = sum / count
ELSE
   average = 0.0
END IF

WRITE (*, *) 'Average = ', average

END PROGRAM

