Question

when I use the INTEGER in declaration in this code, I have no error with gfortran, but when I use REAL in declaration, I have this error:

Error: Type mismatch in argument 'a' at (1); passed INTEGER(4) to REAL(4)

here is my code:

Program workout
IMPLICIT none
REAL :: resultat

resultat = moyen(100,50)
WRITE(*,*) resultat

CONTAINS
  REAL FUNCTION moyen(a,b)
    IMPLICIT none
    REAL,INTENT(IN) :: a, b

    moyen = (a - b)/2
  END FUNCTION moyen

End Program workout

thanks for your time

Was it helpful?

Solution

The error message is quite explicit, you are passing an integer argument to a function which expects a real argument. You could change this line

resultat = moyen(100,50)

to

resultat = moyen(100.0,50.0)

In fact, as you can see, you are making the same mistake twice in one line, the compiler is just identifying the first occurrence.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top