PROGRAM aboveavg
!
! Author:  Br. David Carlson
!
! Date:  March 2, 2000
!
! Revised:  May 2, 2004
!
! This program prompts the user to enter the number of data items and then
! asks for the data items (floats).  The average of the items is computed and
! printed, and all items above this average are printed.

IMPLICIT NONE

INTEGER, PARAMETER::max = 12

REAL, DIMENSION(max)::item
REAL::average, sum
INTEGER::count, k

WRITE (*, *) 'Enter the number of data items to be processed:'
READ (*, *) count

IF (count > max) THEN
   WRITE (*, *) 'Can only handle up to the following number of items: ', max
ELSE IF (count <= 0) THEN
   WRITE (*, *) 'Number of data items must be greater than 0.'
ELSE
   sum = 0.0
   DO k = 1, count
      WRITE (*, *) 'Enter a floating point number:'
      READ (*, *) item(k)
      sum = sum + item(k)
   END DO

   average = sum / count
   WRITE (*, *)
   WRITE (*, 100) 'The average of the data items is: ', average
   WRITE (*, *)
   WRITE (*, *) 'List of above average data items:'

   DO k = 1, count
      IF (item(k) > average) THEN
         WRITE (*, 200) item(k)
      END IF
   END DO
END IF

100 FORMAT (' ', A, F12.4)
200 FORMAT (' ', T5, F12.4)

END PROGRAM

