fortran情况下的文本输入?

问题描述 投票:0回答:1

我正在用fortran编写一段代码:

write(*,*) "What do you want to do?"
      read(*,*) question
      select case(question)
      case(1)
      call sleep (1)
      goto 10 (returns at the beginning)
      case default
      write(*,*) "Ok, then good job :)"
      write(*,*) "I exit in 3 seconds..."
      call sleep (1)
      write(*,*) "I exit in 2 seconds.."
      call sleep (1)
      write(*,*) "I exit in 1 seconds."
      call sleep (2)
      goto 20 (kills the program)

我想使用“是”和“否”代替“ 1”和“ 2”我怎样才能做到这一点?谢谢!

fortran gfortran
1个回答
0
投票

这里是在选择/大小写块中使用字符串(“标题”)的示例:

https://pages.mtu.edu/~shene/COURSES/cs201/NOTES/chap03/select.html

CHARACTER(LEN=4) :: Title
INTEGER          :: DrMD = 0, PhD = 0, MS = 0, BS = 0, Others = 0

SELECT CASE (Title)
   CASE ("DrMD")
      DrMD = DrMD + 1
   CASE ("PhD")
      PhD = PhD + 1
   CASE ("MS")
      MS = MS + 1
   CASE ("BS")
      BS = BS + 1
   CASE DEFAULT
      Others = Others + 1
END SELECT
© www.soinside.com 2019 - 2024. All rights reserved.