I´m trying to read the array below. What i want to do is just verify if the number 1 and 2 exists at the same time in the array. The problem is with my method. I keep getting an "use of unassigned local variable 'jogavel1'", that is inside my method. Can someone help or explain what i am doing wrong? Thanks a lot for your participation =).
int[,] tabuleiro = new int[8, 8] {
{1, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 1, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 2, 0, 2, 0, 2, 0, 2},
{2, 0, 2, 0, 2, 0, 2, 0},
{0, 2, 0, 2, 0, 2, 0, 2},
};
int numero = verificar(tabuleiro);
Console.ReadKey();
}
public static int verificar(int[,] tabuleiro) {
int jogavel, jogavel1, jogavel2 = 0;
for (int i = 0; i < 7; i++) {
for (int a = 0; a < 7; a++) {
if (tabuleiro[i, a] == 1) {
jogavel1++;
}
else if (tabuleiro[i, a] == 2) {
jogavel2++;
}
}
}
if (jogavel1 > 0 && jogavel2 > 0) {
jogavel = 1;
}
else
jogavel = 0;
return jogavel;
}
}