Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28457 Discussions

Fortran Error: The number of subscripts is incorrect

crash1010
Beginner
1,357 Views

Hi! I'm a complete beginner in programming and Fortran. This subroutine is part of a mastermind game where the computer guesses my 4 digit color code (6 colors to chose from) . After the computer guesses a random code the user can input the number of  black sticks (if colors are on the right spot and the right color) and the number of white sticks (if the colors are right but not on the right spot). After compiling this subroutine called 'solve' I got many errors about the matrix where i want to store 0 and 1 (for possible and not possible colour codes). Can anybody help my how to define this matrix and what my errors mean? 

Thanks a lot in advance.

Subroutine SOLVE(n, sN, wN, field)
IMPLICIT NONE

INTEGER :: sN, wN, aus, l, k, j, i, n, sB(n), wB(n)
INTEGER, DIMENSION (10,4) :: field

aus = 0          !at the beginning there are 0 eliminated combinations

! this loop goes through every possible colour combination (6x6x6x6)
DO l = 1, 6, 1
   DO k = 1, 6, 1
      DO j = 1, 6, 1
         DO i = 1, 6, 1
            IF (n == 1) THEN  !in the first round n of the game every combination is         still possible therefore the matrix A should be set to 0
            A(l,k,j,i)="0"
            ELSE
            A(l,k,j,i)="0" !after the second round another program called         "bewertung" (in german this means "evaluation") checks if the user input matches the codes 

             CALL Bewertung (spielfeld(n),l,k,j,i,sB(n),wB(n))
              IF ((sN(n)==sB(n)) .and. (wN(n)==wB(n))) THEN !if they match then the numbers should stay the same and the entries in the matrix should stay the same too
              field(n+1,1)= l
              field(n+1,2)= k
              field(n+1,3)= j
              field(n+1,4)= i
              ELSE
              A(l,k,j,i)= "1"
             aus = aus + 1
             ENDIF
             ENDIF
       ENDDO
     ENDDO
   ENDDO
ENDDO

END SUBROUTINE

 

--------------------------------------------------------------------------------------

Here are the errors I got:

loesen.f(17): error #6410: This name has not been declared as an array or a function. [A]
A(l,k,j,i)="0"
--------------------^
loesen.f(19): error #6410: This name has not been declared as an array or a function. [A]
A(l,k,j,i)="0" !ab der zweiten Runde wird geschaut, ob die Kombiantionen von der eingabe des Nutzers übereinstimmen mit den noch möglichen Kombis in der Matrix
----------------^
loesen.f(20): error #6351: The number of subscripts is incorrect. [SPIELFELD]
CALL Bewertung (spielfeld(n),l,k,j,i,sB(n),wB(n))
-------------------------------------^
loesen.f(27): error #6410: This name has not been declared as an array or a function. [A]
A(l,k,j,i)= 1
-----------------------^
compilation aborted for loesen.f (code 1)

0 Kudos
1 Solution
mecej4
Honored Contributor III
1,331 Views

Error messages from a failed compilation are often hard to understand, but in this case they are very clear. The two variables Spielfeld and A have not been declared as arrays. Apparently (I am guessing), you want Spielfeld to be a 1-dimensional array and A to be a 4-dimensional array.

There is also an ambiguity in the statement

     CALL Bewertung (spielfeld(n),l,k,j,i,sB(n),wB(n))

The first argument, SPIELFELD(n), in the absence of a declaration for SPIELFELD as an array, would be treated as the value of a REAL-valued function that takes a single integer argument, n. Similarly, A could have been intended to be a CHARACTER or REAL-valued function of four integer arguments.

View solution in original post

2 Replies
mecej4
Honored Contributor III
1,332 Views

Error messages from a failed compilation are often hard to understand, but in this case they are very clear. The two variables Spielfeld and A have not been declared as arrays. Apparently (I am guessing), you want Spielfeld to be a 1-dimensional array and A to be a 4-dimensional array.

There is also an ambiguity in the statement

     CALL Bewertung (spielfeld(n),l,k,j,i,sB(n),wB(n))

The first argument, SPIELFELD(n), in the absence of a declaration for SPIELFELD as an array, would be treated as the value of a REAL-valued function that takes a single integer argument, n. Similarly, A could have been intended to be a CHARACTER or REAL-valued function of four integer arguments.

crash1010
Beginner
1,298 Views

Thanks a lot for the reply! It works now.

0 Kudos
Reply