if-statementfortran

Fortran if statement errors


I have a program that is supposed to tell a user if a temperature they entered is absolute zero. If indeed it is, then they should see "no entropy for you", if it is greater, then It should tell them how far above a0 they are, but i keep getting messages saying my if statements have errors, and have no idea where to start, can anyone help me out here?

PROGRAM Project2

CHARACTER(1):: tempType
REAL:: k, f, c
REAL:: temp
REAL:: answer

PRINT *, "What is the temperature type?"
READ *, tempType
PRINT *, "whats the temp?"
READ *, temp

k = 0.0
c = -273.15
f = -459.67

answer = getMinTemperature(tempType)
PRINT *, answer


CONTAINS

FUNCTION getMinTemperature(tempType)
REAL:: getMinTemperature
CHARACTER(1), INTENT(IN):: tempType
REAL:: temp
DO i = 1, num
IF(ACHAR(tempType(i)) <= temp .AND. k > temp) THEN
 k= 0.0
 getMinTemperature = k
 EXIT
ELSE IF (c <= temp .AND. c > temp) THEN
 c= -273.15
 getMinTemperature = c
 EXIT
ELSE IF ( f <= temp .AND. f > temp) THEN
 f=-459.67
 getMinTemperature = f
 EXIT
END IF
END DO

END FUNCTION

END PROGRAM Project2

Solution

  • Assuming it's a homework, I'll just give you a couple of pointers rather than the answer. First of all, reconsider the logic of your program. Do you really need that loop over i? Then, look up the first google hit for achar. Do you really need it? Also notice that your code compiles if you comment out the line with achar, so that it is the latter which interferes with the intent(in) attribute of the function argument.