Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. static void Main(string[] args)
  2.         {
  3.             Random ranNumberGenerator = new Random();
  4.             int firstNumber  = ranNumberGenerator.Next(1, 5);
  5.             int secondNumber = ranNumberGenerator.Next(1, 5);
  6.             int thirdNumber  = ranNumberGenerator.Next(1, 5);
  7.  
  8.             Console.WriteLine("Guess the three lottery numbers (1-4).");
  9.             int firstInput  = Convert.ToInt32(Console.ReadLine());            
  10.             int secondInput = Convert.ToInt32(Console.ReadLine());            
  11.             int thirdInput  = Convert.ToInt32(Console.ReadLine());
  12.  
  13.             int[] lottoNumbers = {firstNumber, secondNumber, thirdNumber};
  14.             int totalMatched = 0;
  15.             totalMatched += calculateMatch(lottoNumbers, firstInput);
  16.             totalMatched += calculateMatch(lottoNumbers, secondInput);
  17.             totalMatched += calculateMatch(lottoNumbers, thirdInput);
  18.  
  19.             int moneyAwarded = 0;
  20.             if (totalMatched == 1)
  21.             {
  22.                 moneyAwarded = 10;
  23.             } else if (totalMatched == 2)
  24.             {
  25.                 moneyAwarded = 100;
  26.             // All 3 match, and in order.
  27.             } else if (totalMatched == 3 && firstNumber == firstInput && secondNumber == secondInput && thirdNumber == thirdInput)
  28.             {
  29.                 moneyAwarded = 10000;
  30.             // If we get here and total matched is 3, that means they were not in order.
  31.             } else if (totalMatched == 3)
  32.             {
  33.                 moneyAwarded = 1000;
  34.             }
  35.             Console.WriteLine("The lotto numbers were {0}, {1}, {2}", firstNumber, secondNumber, thirdNumber);
  36.             Console.WriteLine("You received ${0}!", moneyAwarded);
  37.             Console.ReadLine();
  38.         }
  39.  
  40.         static int calculateMatch(int[] lottoNumbers, int playerInput)
  41.         {
  42.             for (int i = 0; i < lottoNumbers.Length; i++)
  43.             {
  44.                 if (lottoNumbers[i] == playerInput)
  45.                 {
  46.                     lottoNumbers[i] = -1;
  47.                     return 1;
  48.                 }
  49.             }
  50.             return 0;
  51.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement