The code is below:
program error
implicit none
real :: l,h
integer :: r
l=1.0
h=0.2
r=l/h
print*,r
end program error
The problem is that the answer is 4. When I explicitly divide 1.0 by 0.2, the answer is 5, but when I use symbols, it is 4. In addition, for instance, 1.0/h
and l/0.2
is also 4. I am really confused.
When I define r
as real number, the problem is gone; but I need it to be an integer since I am going to use those variables to define a two dimensional array.