My Wizard Console!

Recently, I just got into programming. I didn’t have much previous experience in it. Since my problem is connected to this Section, but not to any specific lecture, don’t mind me that I posted here.

Following your Lectures I made my own Wizard console and I thought I can add some features. I build in a counter that counts the number of hints and also tried adding some if statements to change the “guessing lines” so it will be less monotonous.

But my problem is with the counter is that if the right number is found you can still use up and down arrows before you hit Enter. The counter can go on without any change in the guessed number because the algorithm already found it.

I would be grateful, if you can run over it and help me with a solution! I uploaded my code in pictures!



Thanks,
Gergő Modrovics

Declare at the beginning:
bool found = false;

Replace
guess = (min + max) / 2;
with

int previousGuess = guess;
guess = (min + max) / 2;
if (previousGuess == guess)
{
    found = true;
}

and add

if (found)
{
    return;
}

at the beginning of Update() to stop guessing.

You can copy code from Visual Studio with Ctrl + A, Ctrl + C and paste here with the Preformatted text button: </>

1 Like

Privacy & Terms