-3

iam making a tic tac toe on QBasic but I have a problem with a function and i don't know fix it The error is "Expected ) on current line" but i don't know where put )

FUNCTION HayGanador() as string  'the error is on this line
    FOR i = 1 TO 3
        IF Tablero(i, 1) <> "" AND Tablero(i, 1) = Tablero(i, 2) AND Tablero(i, 1) = Tablero(i, 3) THEN
            HayGanador = -1
            EXIT FUNCTION
        END IF

        IF Tablero(1, i) <> "" AND Tablero(1, i) = Tablero(2, i) AND Tablero(1, i) = Tablero(3, i) THEN
            HayGanador = -1
            EXIT FUNCTION
        END IF
    NEXT i

    IF Tablero(1, 1) <> "" AND Tablero(1, 1) = Tablero(2, 2) AND Tablero(1, 1) = Tablero(3, 3) THEN
        HayGanador = -1
        EXIT FUNCTION
    END IF
    IF Tablero(1, 3) <> "" AND Tablero(1, 3) = Tablero(2, 2) AND Tablero(1, 3) = Tablero(3, 1) THEN
        HayGanador = -1
        EXIT FUNCTION
    END IF
    HayGanador = 0
END FUNCTION

I was trying to enter a function that identifies the winner of the tic tac toe game but I don't know how to make this function a string

  • see: https://en.wikibooks.org/wiki/QBasic/Subroutines_and_Functions#Declaring_a_function "Functions are declared in the same way as variables - it returns the variable type it's defined to return, in the same way variables are defined to contain their specified type. By default, it is a number, but appending a dollar sign indicates that it is returning a string." – Luuk May 19 '23 at 16:39

1 Answers1

0

I guess this is correct syntax:

   FUNCTION HayGanador$()
FOR i = 1 TO 3
    IF Tablero(i, 1) <> "" AND Tablero(i, 1) = Tablero(i, 2) AND Tablero(i, 1) = Tablero(i, 3) THEN
        HayGanador = -1
        EXIT FUNCTION
    END IF
...

Your syntax which is throwing error is syntax possible in Visual Basic, but not in QBasic. In QB you can only define function return type using shorthands !, #, %, &, $ for single, double, integer, long and string respectively