Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There were two errors in your program. First, before using a variable it must always be initialized. If you look at the different paths your <code>playAgain</code> variable can take, the value is only set in your <code>if (guessCount++ == maxGuesses)</code> path. If the condition is false, you'll get to the <code>while</code> part without any value. You can change the declaration to </p> <pre><code>char playAgain = 'n'; </code></pre> <p>The second error was a missing bracket. If you carefully do the indentation, you will see this :</p> <pre><code>do { //Bunch of code if (guessCount++ == maxGuesses) { //INCRIMENT GAME COUNT gameCount++; Console.WriteLine("You lost"); //DISPLAY CORRECT NUMBER IF TOO MANY INCORRECT GUESSES Console.WriteLine("\nThe number was {0},better luck next time!", randomNumber); guessCount = 1; //PROMPT TO PLAY AGAIN Console.WriteLine("Would you like to play again? (Y/N)"); playAgain = char.Parse(Console.ReadLine()); } while (playAgain == 'y' || playAgain == 'Y'); </code></pre> <p>as you can see, you're missing the <code>if</code> bracket, it should be </p> <pre><code> playAgain = char.Parse(Console.ReadLine()); } } while (playAgain == 'y' || playAgain == 'Y'); </code></pre> <p>Also, there are a <em>LOT</em> of things you could improve. For example, you should place your variable declarations where they are used not at the top of the class. Each comment should be a separate method; it would be way easier for you to follow your flowchart if your Main, instead of being a huge blob of code was something like:</p> <pre><code>private static void Main(string[] args) { WelcomeTheUser(); InitializeWinCountAndGameCount(); Play(); DisplayWinCount(); } </code></pre> <p>You could also avoid a ton of misplaced brackets if you keep your functions small.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload