title: C# mastermind game
body: <p>In the Main method, in the for loop, if you copy/paste/run whole program in visual, you'll see that i'm trying to end the game. First "if", if the user hasn't guessed; then attempts decrements by one and keeps guessing. The second "else if", if the user has guessed the PCArray, than the game ends and message shows. those work.</p>
  
  <p>But, the first "else if", if the user has exhausted his attempts to guess, and hasn't guessed PCArray, than it should say "oh no, you couldn't guess..." Why is this not working.</p>
  
  <p>I just want it to work so that if:
  - user hasn't guessed but still has attempts, attempts decrements by 1 until 0.
  - user has guessed the correct number, it says congrats.
  - attempts are 0 and user still hasn't guessed number, then show "oh no..." message.</p>
  
  <pre><code>  class Program
          {
              static void Main(string[] args)
              {
                  string name;
  
                  Console.WriteLine("**************Let's play Master-Mined**************");
                  Console.WriteLine();
                  Console.Write("Please enter your name: ");
                  name = Console.ReadLine();
                  Console.WriteLine("Welcome {0}. Have fun!! ", name);
  
                  int numberCount = 0;
                  int difficultyLevel = 0;
  
                  int digitNumber = GetRandomNumberCount(numberCount);
                  Console.Write(digitNumber + " it is. Let's play.");
                  Console.WriteLine();
                  int[] PCArray = GenerateRandomNumbers(digitNumber);
  
                  Console.WriteLine("A " + digitNumber + "-digit number has been chosen. Each possible digit may be the number 1, 2, 3 or 4.");
                  Console.WriteLine("    ******");
  
                  int difficulty = GetGameDifficulty(difficultyLevel);
                  int attempts = difficulty * digitNumber;
  
                  Console.WriteLine("Enter your guess ({0} guesses remaining)", attempts);
                  int remaining = attempts;
  
                  for (int i = 0; i &lt; attempts; i++)
                  {
                      int[] userArray = GetUserGuess(digitNumber);
                      int hits = CountHits(PCArray, userArray, attempts);
  
                      if ((hits != PCArray.Length) &amp;&amp; (attempts &gt; 0))
                      {
                          remaining--;
                          Console.WriteLine("Enter your guess ({0} guesses remaining)", remaining);
                      }
                      else if ((attempts &lt; 1))
                      {                    
                          Console.WriteLine("Oh no {0}! You couldn't guess the right number.", name);
                          Console.WriteLine("The correct number is: ");
                          for (int j = 0; j &lt; PCArray.Length; j++)
                          {
                              Console.Write(PCArray[j] + " ");
                          }
                          Console.WriteLine("Would you like to play again (Y/N)? ");
                      }
                      else if (hits == PCArray.Length)
                      {
                          attempts = 0;
                          Console.WriteLine("You win {0}!", name);
                          Console.WriteLine("The correct number is:");
                          for (int j = 0; j &lt; PCArray.Length; j++)
                          {
                              Console.Write(PCArray[j] + " ");
                          }
                      }
                  }
                  Console.ReadLine();
              }        
              public static int GetRandomNumberCount(int numberCount)
              {
                  int number = 0;
                  do
                  {
                      try
                      {
                          Console.Write("How many numbers would you like to use in playing the game (4-10)? ");
                          number = int.Parse(Console.ReadLine());
                          Console.WriteLine();
                      }
                      catch
                      {
                          Console.WriteLine("You must pick a number between 4 and 10. Choose again.");
                          Console.WriteLine();
                      }
                  } while ((number &lt; 4) || (number &gt; 10));
  
                  return number;
              }
              public static int GetGameDifficulty(int difficultyLevel)
              {
                  int difficulty = 0;
  
                  do
                  {
                      try
                      {
                          Console.Write("Choose a difficulty level (1=hard, 2=medium, 3=easy): ");
                          difficulty = int.Parse(Console.ReadLine());
                      }
                      catch
                      {
                          Console.WriteLine("         Incorrect entry: Please re-enter.");
                      }
                  } while ((difficulty &lt; 1) || (difficulty &gt; 3));
  
                  return difficulty;
              }
              public static int[] GenerateRandomNumbers(int PCSize)
              {
                  int eachNumber;
                  int[] randomNumber = new int[PCSize];
                  Random rnd = new Random();
  
                  for (int i = 0; i &lt; randomNumber.Length; i++)
                  {
                      eachNumber = rnd.Next(1, 5);
                      randomNumber[i] = eachNumber;
                      Console.Write(eachNumber);
                  }
                  Console.WriteLine();
                  return randomNumber;
              }
              public static int[] GetUserGuess(int userSize)
              {
                  int number = 0;
                  int[] userGuess = new int[userSize];
                  for (int i = 0; i &lt; userGuess.Length; i++)
                  {
                      Console.Write("Digit {0}: ", (i + 1));
                      number = int.Parse(Console.ReadLine());
                      userGuess[i] = number;
                      //Console.Write(number);
                  }
                  Console.WriteLine();
                  Console.Write("Your guess: ");
                  for (int i = 0; i &lt; userGuess.Length; i++)
                  {
                      Console.Write(userGuess[i] + " ");
                  }
                  Console.WriteLine();
                  return userGuess;
              }
              public static int CountHits(int[] PCArray, int[] userArray, int attempts)
              {
                  int hit = 0;
                  int miss = 0;
                  int hits = 0;
  
                  for (int i = 0; i &lt; PCArray.Length; i++)
                  {
                      if (PCArray[i] == userArray[i])
                      {
                          hit = hit + 1;
                          hits = hit;
                      }
                      else
                      {
                          miss = miss + 1;
                      }
                  }
                  Console.WriteLine("Results: {0} Hit(s), {1} Miss(es)", hit, miss);
                  return hits;
              }
          }
  </code></pre>