'*' and '/' not recognized on input by a read statement

前端 未结 2 2047
Happy的楠姐
Happy的楠姐 2020-11-28 17:06

I start learning Fortran and I\'m doing a little case test program where the user types two real numbers and selects an arithmetic operators (from + - * /). The following e

2条回答
  •  伪装坚强ぢ
    2020-11-28 17:33

    Ok then the correct source code is

    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 (*,"(A1)") 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 ',res 
    
    end program operateur
    

提交回复
热议问题