! This is a basic starting shell for your programs MODULE const INTEGER, PARAMETER :: dp = KIND(1.0d0), sp = KIND(1.0e0) REAL(KIND=dp), PARAMETER :: dpi = 3.141592653589793d0 END MODULE const ! PROGRAM prog USE const IMPLICIT NONE ! ! Program to compute the average of a series of positive ! integers ! ! Note that average is a double precision value even though ! total and n are integers. INTEGER :: rvalue, total, n REAL(kind=dp) :: avg ! Initialize the accumulation variables to 0 total = 0 n = 0 DO WRITE(*,*) 'Input next integer' READ(*,*) rvalue IF( rvalue < 0) THEN EXIT ENDIF total = total + rvalue n = n + 1 ENDDO ! Compute the average. Note that avg = total/n is an integer ! division, so you need to modify the calculation so that a double ! precision division is performed. avg = total/DBLE(n) ! Other ways to do this: ! avg = DBLE(total)/n ! avg = DBLE(total)/DBLE(n) ! avg = 1.0d0*total/n ! avg = total/(1.0d0*n) WRITE(*,*) 'Final total = ',total WRITE(*,*) 'number of values = ',n WRITE(*,*) 'average = ',avg END PROGRAM prog !!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Input next integer ! 1 ! Input next integer ! 2 ! Input next integer ! 3 ! Input next integer ! 4 ! Input next integer ! 5 ! Input next integer ! -6 ! Final total = 15