Thought I'd screwed up but

So I went through this section and the next to see if this bug was fixed. I structured my code slightly differently than the course, because I tended to go ahead before the videos were complete and jump into challenges, and even look up things ahead of them being revealed. Now I never saw this bug on video, but I found that if I implemented my code in the way the course was showing I came across a bug where max and min could invert positions (For Example min being greater than 1000, while max stayed at that value, making the guess higher than 1000). I thought about this and implemented this solution:

public void GuessHigher()
{
    if (min < max)
    {
        min = guess + 1;
        NextGuess();
    }
    
}

public void GuessLower()
{
    if (max > min)
    {
        max = guess - 1;
        NextGuess();
    }
}

This seems to work for me to ceiling/limit the values. If anyone has a better solution I’d love to hear it. My function names might be a little different but I implemented them before the video showed what they were called in the course. Hope this helps anyone else if they come across this bug!

Privacy & Terms