avrg.f90

I suggest you either typed  this as it appears into the compiler, or as an easier way, just copy and paste it!

Note: I do not claim the program will 100% work, but I give it my best. If it doesn't, try tweaking it yourself, or email me about it, and I'll modify and post the improved version later. Good luck!

 

 

PROGRAM avrg
IMPLICIT NONE

!Declaration block
REAL :: input_num, sum, average
INTEGER :: n, count_n


!The average calculation block
PRINT* 
PRINT*
PRINT*, "Please tell me how many numbers you want to calculate:"
READ*, n
PRINT*

DO WHILE (n<0)
PRINT*, "Please input a positive integer.Try again."
PRINT*, "Please tell me how many numbers you want to calculate:"
READ*, n
PRINT*
END DO
!Counter used to utilise the DO WHILE loop
count_n =0 !Sets the counter to zero (0)
sum=0 !Sets sum to zero (0) to facilitate correct arithmatic answers
!The DO WHILE loop structure 
DO WHILE (count_n<=n-1) 
count_n=count_n+1
1 PRINT*, "Please input the numbers now..."
READ*, input_num
IF (input_num<-1) THEN
PRINT*, "That is an invalid input. Try again."
GOTO 1
ELSE IF (-1<input_num .AND. input_num<0) THEN
PRINT*, "That is an invalid input. Try again."
GOTO 1
ELSE IF (input_num==-1) THEN
PRINT*, "Flag value input. Program will be terminated."
GOTO 2
ELSE
END IF
sum=sum+input_num !The all important equation
END DO

!Printout block
average=sum/n
PRINT*
PRINT*, "The sum of the numbers you have just entered is", sum
PRINT*, "Thus the average calculated is", average
PRINT*
PRINT*, "Thank you for using ADCY Averaging Calculator"
2 PRINT*, "Have a nice day :)"



!Program's end
END PROGRAM avrg