728x90
반응형
! 온도변환 인터페이스 사용 버전 p222
PROGRAM Temperature_Conversion_7
implicit none
INTERFACE
Function Celsius_to_Fahr(Temp)
real :: Celsius_to_Fahr
real, intent(in) :: Temp
END Function Celsius_to_Fahr
END INTERFACE
real :: fahrenheit, celsius
character(1) :: response
DO
! Get a Celsius temperature
write (*, '(1x, A)', ADVANCE = "NO") "Enter a Celsius temperature:"
read *, Celsius
! Use the module function Fahr_to_Celsius to convert it to Celsius
Fahrenheit = Celsius_to_Fahr(celsius)
! Output the result
print '(1x, 2(F6.2, A))', celsius, &
" in Celsius is equivalent to ", fahrenheit, " in Fahrenheit"
! Check if more temperautre ar to ber converted
write (*, '(/ 1x, A)', ADVANCE = "NO") &
"More temperatures to convert (Y or N)?"
read *, response
IF (response /= "Y") EXIT
END DO
pause
END PROGRAM Temperature_Conversion_7
Function Celsius_to_Fahr(Temp)
implicit none
real :: Celsius_to_Fahr
real, intent(in) :: Temp
Celsius_to_Fahr = (Temp - 32.0) /1.8
End Function Celsius_to_Fahr
728x90
반응형