gandalf458
IS-IT--Management
Hi. It has been over 35 years since I wrote my last Fortran program and that was in Fortran IV and on punched cards! I have just installed gfortran (Fortran 95) on my Linux box and have written my first simple program:
program f2c2f
! convert degrees C to F and F to C
implicit none
real :: x, c, f
print*, 'Enter a number:'
read*, x
c = (x - 32) * 5 / 9
f = x * 9 / 5 + 32
2010 format(f6.2, ' deg F = ', f6.2, ' deg C.')
2020 format(f6.2, ' deg C = ', f6.2, ' deg F.')
print 2010, x, c
print 2020, x, f
end program f2c2f
It works fine but there's just one thing I would like to change if possible. I would like the prompt on the same line as the entry of the number. I thought it was possible to add a format to the Read statement and I have tried in various ways to do this without success. All the online guides seem to gloss over formats on read statements and I'm not sure if they can contain literals.
Can any kind soul help please?
program f2c2f
! convert degrees C to F and F to C
implicit none
real :: x, c, f
print*, 'Enter a number:'
read*, x
c = (x - 32) * 5 / 9
f = x * 9 / 5 + 32
2010 format(f6.2, ' deg F = ', f6.2, ' deg C.')
2020 format(f6.2, ' deg C = ', f6.2, ' deg F.')
print 2010, x, c
print 2020, x, f
end program f2c2f
It works fine but there's just one thing I would like to change if possible. I would like the prompt on the same line as the entry of the number. I thought it was possible to add a format to the Read statement and I have tried in various ways to do this without success. All the online guides seem to gloss over formats on read statements and I'm not sure if they can contain literals.
Can any kind soul help please?