New to Fortran (just started today), having trouble with the natural logarithm:
PROGRAM log
IMPLICIT NONE
REAL :: x
PRINT *, "Enter a number:"
READ *, x
x = log (x)
PRINT *, "The natural log of x is:", x
END PROGRAM log
The compiler keeps throwing up the error:
x = log (x)
1
Error: Symbol at (1) is not appropriate for an expression
Other intrinsic functions work fine. What am I doing wrong?
The problem is that you've shadowed (overridden) the definition of the symbol log
- which would normally refer to the standard library mathematical function - with the name of your program, which is also log
. If you change the name of the program to, say, logtest
:
PROGRAM logtest
...
END PROGRAM logtest
You'll find that the program works as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With