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 error appears when the user selects "*"
F6502 : read <con> - positive integer expected in repeat field
and if the user selects "/" the compiler executes the default case, and displays this message
invalid operator, thanks
the result is 0.000000E+00
The program is as follows.
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 ',res
end program operateur
See Question&Answers more detail:os