First of all explain that the "exercise" that I try to do is a small set of pairs, in which you enter some coordinates and you are shown the value stored in that coordinate. At the moment that two of the values of the coordinates that you have entered are equal (for example, I put (0,1) and I get 3, then I put (2,4) and I get 3. If I left 4 I would ask again coordinates for the two values) should exit from the [...] while. I have the following problem and that no matter how much I think about it, I can not solve:
When selecting a number from within the matrix, I am saved and I can not change the value that I have to get from the matrix the second time I enter the numbers. He prints only the first number, the second never, he copies it from the first one.
The variable "sig" is not in use to check that the numbers that are chosen from the matrix are different.
static void Main(string[] args)
{
int[,] matriz2 = new int[5, 5];
Random ale = new Random();
bool acierto = false;
int guardo = 0, guardo2 = 16;
int intentos = 0;
string sig = "?";
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
matriz2[i, j] = ale.Next(0, 11);
Console.Write("\t{0}", matriz2[i, j]);
}
Console.WriteLine();
}
do
{
Console.WriteLine("Introduzca las coordenadas.");
int numero = int.Parse(Console.ReadLine());
int numero2 = int.Parse(Console.ReadLine());
Console.Write("Mostramos el valor: ");
Console.WriteLine(funcion1(matriz2, numero, numero2));
guardo = matriz2[numero, numero2];
if (guardo == guardo2)
acierto = true;
guardo2 = guardo;
intentos++;
} while (acierto != true);
Console.Read();
}
static int funcion1(int[,] ar, int num1, int num2)
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
ar[i, j] = ar[num1, num2];
}
}
return ar[num1, num2];
}
}
}