Function expected ) on tic tac toe game

44 views Asked by At

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

1

There are 1 answers

1
Matěj Kasper On

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