I'm trying to make a Computer Vs. Computer guessing game. I've done it on python and matlab, but im having trouble doing it with c#.
I dont think that the application is executing the loop, but when using the debugger to step through the application it appears to work as intended.
using System;
using static System.Console;
namespace ComVsCom
{
class ComVsCom
{
static void Main(string[] args)
{
int rand, comp, pick = 0;
bool tri = false;
Random number = new Random();
rand = number.Next(1, 10);
Random computer = new Random();
comp = computer.Next(1, 10);
while (comp != rand && tri == false)
{
if (comp > rand)
WriteLine("Guess again you are too high!");
if (comp < rand)
WriteLine("Guess again you are too low!");
pick++;
WriteLine("{0} attempt", pick);
comp = computer.Next(1, 10);
if (comp == rand)
{
WriteLine("You got it! it took you {0} times the number was {1}", pick, rand);
tri = true;
}
}
}
}
}
Running the program normally, it terminates gives no output. However, when debugging the output given is what was expected and is something like:
Guess again you are too high!
3 attempt
Guess again you are too low
6 attempt
You got it! it took you 3 times the number was 6
Why does this work when using the debugger and not when running the program normally?