PROGRAM Temperature_Conversion_3 !----------------------------------------------------------------------- ! Program to convert several Fahrenheit temperatures to the ! corresponding Celsius temperatures. The function Fahr_to_Celsius ! is used to perform the conversions. Identifiers used are: ! Fahr_to_Celsius : external function subprogram that converts ! Fahrenheit temperatures to Celsius ! FahrenheitTemp : a Fahrenheit temperature to be converted ! CelsiusTemp : the corresponding Celsius temperature ! Response : user response to "More data?" query ! ! Input: FahrenheitTemp, Response ! Output: CelsiusTemp !----------------------------------------------------------------------- REAL :: Fahr_to_Celsius REAL :: FahrenheitTemp, CelsiusTemp CHARACTER(1) :: Response DO ! Get a Fahrenheit temperature WRITE (*, '(1X, A)', ADVANCE = "NO") "Enter a Fahrenheit temperature: " READ *, FahrenheitTemp ! Use the external function Fahr_to_Celsius to convert it to Celsius CelsiusTemp = Fahr_to_Celsius(FahrenheitTemp) ! Output the result PRINT '(1X, 2(F6.2, A))', FahrenheitTemp, & " in Fahrenheit is equivalent to ", CelsiusTemp, " in Celsius" ! Check if more temperatures are to be converted WRITE (*, '(/ 1X, A)', ADVANCE = "NO") & "More temperatures to convert (Y or N)? " READ *, Response IF (Response /= "Y") EXIT END DO END PROGRAM Temperature_Conversion_3 !- Fahr_to_Celsius -------------------------------------------- ! Function to convert a Fahrenheit temperature to Celsius ! Accepts: A temperature Temp in Fahrenheit ! Returns: The corresponding Celsius temperature !-------------------------------------------------------------- FUNCTION Fahr_to_Celsius(Temp) IMPLICIT NONE REAL:: Fahr_to_Celsius REAL, INTENT(IN) :: Temp Fahr_to_Celsius = (Temp - 32.0) / 1.8 END FUNCTION Fahr_to_Celsius