【发布时间】:2019-02-21 14:01:17
【问题描述】:
当我只运行摄氏温度的代码时,我得到的结果低于代码:
program temperature
! F C temperature conversion
implicit none
real :: celcius=0.0, fahrenheit=0.0
integer:: t,n
print *,'enter the number of lines'
read*, n
do n=1,n
print*,'enter the value of t: one per line',n
read*, t
celcius=5/9*(t-32)
enddo
do n=1,n
print*, t, celcius
enddo
end program
结果
enter the number of lines
3
enter the value of t: one per line 1
50
enter the value of t: one per line 2
20
enter the value of t: one per line 3
10
10 0.00000000E+00
10 0.00000000E+00
10 0.00000000E+00
10 0.00000000E+00
很明显,编译器没有在计算中选择t 的值。
【问题讨论】:
-
只有在第一个循环中输入的最后一个值提供了循环外
t的值。如果你想使用多个值,你应该使用一个数组,或者在第一个循环周围重新构造其余部分。