midval.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 midval
IMPLICIT NONE

REAL :: a, b, c, midvalue
CHARACTER :: confirm

PRINT*, "Welcome to ADCY Mid-Val Calculation Program"
PRINT*
PRINT*, "This program here can magically find out any number that is the middle value "
PRINT*, "of three numbers entered by the user. If you don't believe me, try it for"
PRINT*, "yourself."
13 PRINT*
WRITE( UNIT=*,FMT=10,ADVANCE="NO" ) "What should be the first number?"
READ*, a
WRITE( UNIT=*,FMT=10,ADVANCE="NO" ) "And the second number is?"
READ*, b
WRITE( UNIT=*,FMT=10,ADVANCE="NO" ) "Finally the last one is?"
READ*, c

DO WHILE (a==b .OR. a==c .OR. b==c)
PRINT*, "To find the middle value of three numbers, no two numbers can be the same."
PRINT*, "You will have to try again."
GOTO 13
END DO

PRINT*, "And the value is..."
PRINT*, "(drum-roll please)"
PRINT*, "..."
PRINT*, "..."
PRINT*, "..."
PRINT*, midvalue (a, b, c), "!"
PRINT*, "Hooray!"
PRINT*

46 WRITE( UNIT=*,FMT=10,ADVANCE="NO" ) "Do you want to go now? (Y/N)"
READ*, confirm

IF (confirm == "Y" .OR. confirm == "y" ) THEN
GOTO 24
ELSE IF (confirm == "N" .OR. confirm == "n" ) THEN
GOTO 35
ELSE
PRINT*, "Please be serious. Y or N only OKAY!"
PRINT*, "Sooo... try again."
GOTO 46
END IF

35 PRINT*, "Then carry on..."
GOTO 13

24 PRINT*, "Thank you for using ADCY Mid-Val Calculation Program"
PRINT*, "Have a nice day:)"

10 FORMAT ( A )

END PROGRAM midval
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FUNCTION midvalue (a, b, c)
IMPLICIT NONE

REAL, INTENT (IN) :: a, b, c
REAL :: midvalue

IF ( a>b .AND. a<c ) THEN
midvalue = a 
ELSE IF ( a<b .AND. a>c ) THEN
midvalue = a
ELSE IF ( b>a .AND. b<c ) THEN
midvalue = b
ELSE IF ( b<a .AND. b>c ) THEN
midvalue = b
ELSE IF ( c>a .AND. c<b ) THEN
midvalue = c
ELSE IF ( c<a .AND. c>b ) THEN
midvalue = c 
END IF

END FUNCTION midvalue