FORTRAN 90+: DECLARATION OF VARIABLE EXAMPLES
There were several examples embedded in the Theory discussion. Here is are other short programs to try:
PROGRAM Example1 IMPLICIT NONE INTEGER :: i REAL :: Mach CHARACTER :: ans WRITE(*,*) ’DO YOU WISH TO OUTPUT A REAL OR INTEGER VARIABLE?’ WRITE(*,*) ’R = Real; I = Integer’ READ(*,*) ans IF (ans.eq.’R’) THEN ! It is good practice to use a decimal even for whole numbers Mach= 1.0 WRITE(*,*) ’Mach number is ’, Mach ELSE IF (ans.eq.’I’) THEN ! Notice that no decimal is needed i = 1 WRITE(*,*) ’Integer i is ’, i ELSE WRITE(*,*) ’Your input was not an I or R’ WRITE(*,*) ’Your input was ’, ans STOP ENDIF END PROGRAM Example1
PROGRAM example2 IMPLICIT NONE CHARACTER(LEN=20) :: interest WRITE(*,*) ‘‘Is your interest in Jets,’’ & ‘‘Rotorcraft, or Spacecraft?’’ READ(*,*) interest SELECT CASE (interest) CASE (‘‘Jets’’) WRITE(*,*) ‘‘Work for Boeing’’ CASE (‘‘Rotorcraft’’) WRITE(*,*) ‘‘Work for Bell’’ CASE (‘‘Spacecraft’’) WRITE(*,*) ‘‘Work for SpaceX’’ END SELECT END PROGRAM