I'm trying to make a counter that will increment based on the response of the user. Here's the code I got so far:
string ok = "";
int z = 0;
test(ok, z);
test1(ok, z);
Console.WriteLine(z);
}
static void test(string ok, int z)
{
bool estok = false;
while (!estok)
{
ConsoleKeyInfo saisie = Console.ReadKey(true);
if (saisie.Key == ConsoleKey.A || saisie.Key == ConsoleKey.B)
{
estok = true;
if (saisie.Key == ConsoleKey.A)
{
z++;
}
if (saisie.Key == ConsoleKey.B)
{
z--;
}
}
else
{
estok = false;
Console.WriteLine("Error");
}
}
}
static void test1(string ok, int z)
{
bool estok = false;
while (!estok)
{
ConsoleKeyInfo saisie = Console.ReadKey(true);
if (saisie.Key == ConsoleKey.A || saisie.Key == ConsoleKey.B)
{
estok = true;
if (saisie.Key == ConsoleKey.A)
{
z++;
}
if (saisie.Key == ConsoleKey.B)
{
z--;
}
}
else
{
estok = false;
Console.WriteLine("Error");
}
}
}
I got 2 functions (test
and test1
) that both increment the int z
. The Console.WriteLine(z)
will return me 0, in place of the 2 i'm waiting for (when the user has 2 correct answers).
I figured that the increment won't happen since it's in the function and that the Console.WriteLine(z)
can't reach the z++
. How can I change that ?
How can I get the result from these?