title: C# Lottery Compare Results
body: <p>I'm new to C# we have an activity to create a lottery game.</p>
  
  <p>1 matching number won $10
  2 matching number won $100
  3 matching number not in order $1,000
  3 matching number in order won $10,000</p>
  
  <p>I'm having issues with my code even there are 2 matching or 3 matching number it always display $10. Any help would be appreciated.</p>
  
  <p>Below are the source code. </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  
  using System.Linq;
  
  using System.Text;
  
  using System.Threading.Tasks;
  
  namespace LotteryGame
  
  {
  class Program
  {
      static void Main(string[] args)
      {
          // Matching numbers awards
          int rNumMatchOne = 10;
          int rNumMatchTwo = 100;
          int rNumMatchThree = 1000;
          int rNumMatchFour = 10000;
  
          // Generate random numbers
          Random randomNum = new Random();
  
          // Integers Declaration
          int rNum1;
          int rNum2;
          int rNum3;
          int rNumIput;
          int guessNum;
  
          // Arrays Declartion
          int[] guessNumMatch = new int[3];
          int[] guessNumSort = new int[3];
          int[] guessInput = new int[3];
  
          // Restrict inputs between 1 and 4 only
          rNum1 = randomNum.Next(1, 5); 
          rNum2 = randomNum.Next(1, 5);
          rNum3 = randomNum.Next(1, 5);
  
          Console.Write("C# Lottery Game\n\n");
  
          Array.Sort(guessNumSort); // sort random numbers
          // Guess number input loop
          for (rNumIput = 0; rNumIput &lt; 3; rNumIput++)
          {
              Console.Write("Guess Number " + (rNumIput + 1) + ": ");
              guessNum = Convert.ToInt32(Console.ReadLine());
  
              // Invalid input between 1 and 4 program will loop back and enter correct number
              while (guessNum &lt; 1 || guessNum &gt; 4)
              {
                  Console.WriteLine("\n");
                  Console.WriteLine("Invalid Number. Please enter number between 1 and 4. \n");
                  Console.Write("Guess Number " + (rNumIput + 1) + ": ");
                  guessNum = Convert.ToInt32(Console.ReadLine());
              }
              guessNumMatch[rNumIput] = guessNum;
              guessNumSort[rNumIput] = guessNum;
          }
          Array.Sort(guessNumSort);
          // Display random numbers and entered numbers
          Console.WriteLine();
          Console.WriteLine("Generated random numbers are   : " + rNum1 + " | " + rNum2 + " | " + rNum3);
          Console.WriteLine("Numbers you entered are        : " + guessNumMatch[0] + " | " + guessNumMatch[1] + " | " + guessNumMatch[2]);
  
  
          // Matching 1 number
          if (guessNumMatch[0] == rNum1 || guessNumMatch[1] == rNum2 || guessNumMatch[2] == rNum3)
          {
              Console.WriteLine("\n");
              Console.WriteLine("CONGRATULATIONS! YOU WON: $" + rNumMatchOne);
          }
          // Matching 2 numbers
          else if ((guessNumMatch[0] == rNum1 &amp;&amp; guessNumMatch[1] == rNum2) || (guessNumMatch[1] == rNum2 &amp;&amp; guessNumMatch[2] == rNum3))
          {
              Console.WriteLine("\n");
              Console.WriteLine("CONGRATULATIONS! YOU WON: $" + rNumMatchTwo);
          }
          // Matching 3 numbers not in order
          else if (guessNumSort[0] == guessInput[0] &amp;&amp; guessNumSort[1] == guessInput[1] &amp;&amp; guessNumSort[2] == guessInput[2])
          {
              Console.WriteLine("\n");
              Console.WriteLine("CONGRATULATIONS! YOU WON: $" + rNumMatchThree);
          }
          // Matching 3 numbers exact order
          else if (guessNumMatch[0] == rNum1 &amp;&amp; guessNumMatch[1] == rNum2 &amp;&amp; guessNumMatch[2] == rNum3)
          {
              Console.WriteLine("\n");
              Console.WriteLine("CONGRATULATIONS! YOU WON: $" + rNumMatchFour);
          }
          else // No matching numbers
          {
              Console.WriteLine("\n");
              Console.WriteLine("SORRY, NO MATCHING NUMBERS FOUND! ");
          }
          Console.WriteLine("\n");
          Console.WriteLine("PRESS ANY KEY TO EXIT PROGRAM ");
          Console.ReadKey();
      }
  }
  }
  </code></pre>