小编ima*_*ine的帖子

读取语句在输入时无法识别'*'和'/'

我开始学习Fortran,我正在做一个小案例测试程序,用户输入两个实数并选择算术运算符(来自+ - */).用户选择"*"时出现以下错误

F6502 : read <con> - positive integer expected in repeat field
Run Code Online (Sandbox Code Playgroud)

如果用户选择"/",编译器将执行默认情况,并显示此消息

invalid operator, thanks
the result is 0.000000E+00
Run Code Online (Sandbox Code Playgroud)

该计划如下.

program operateur
implicit none

   CHARACTER(LEN=1) :: oper 
   real::a,b,res
   print*,'Give the first number a :'
   read*,a
   print*,'Give the second number b :'
   read*,b
   print*,'which operation ?'
   read*,oper
   !print*,'donnez a,b,oper :'
  ! read(*,*)a,b,oper

               select case (oper)

                  case ('+')      
                  res=a+b

                  case ('-')       
                  res=a-b

                  case ('*')       
                  res=a*b


                  case ('/')       
                  res=a/b           

                  case default
                  print*, "Invalid Operator, thanks" 

               end select

   print*,'the result is …
Run Code Online (Sandbox Code Playgroud)

fortran

2
推荐指数
1
解决办法
412
查看次数

标签 统计

fortran ×1