Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- Random ranNumberGenerator = new Random();
- int firstNumber = ranNumberGenerator.Next(1, 5);
- int secondNumber = ranNumberGenerator.Next(1, 5);
- int thirdNumber = ranNumberGenerator.Next(1, 5);
- Console.WriteLine("Guess the three lottery numbers (1-4).");
- int firstInput = Convert.ToInt32(Console.ReadLine());
- int secondInput = Convert.ToInt32(Console.ReadLine());
- int thirdInput = Convert.ToInt32(Console.ReadLine());
- int[] lottoNumbers = {firstNumber, secondNumber, thirdNumber};
- int totalMatched = 0;
- totalMatched += calculateMatch(lottoNumbers, firstInput);
- totalMatched += calculateMatch(lottoNumbers, secondInput);
- totalMatched += calculateMatch(lottoNumbers, thirdInput);
- int moneyAwarded = 0;
- if (totalMatched == 1)
- {
- moneyAwarded = 10;
- } else if (totalMatched == 2)
- {
- moneyAwarded = 100;
- // All 3 match, and in order.
- } else if (totalMatched == 3 && firstNumber == firstInput && secondNumber == secondInput && thirdNumber == thirdInput)
- {
- moneyAwarded = 10000;
- // If we get here and total matched is 3, that means they were not in order.
- } else if (totalMatched == 3)
- {
- moneyAwarded = 1000;
- }
- Console.WriteLine("The lotto numbers were {0}, {1}, {2}", firstNumber, secondNumber, thirdNumber);
- Console.WriteLine("You received ${0}!", moneyAwarded);
- Console.ReadLine();
- }
- static int calculateMatch(int[] lottoNumbers, int playerInput)
- {
- for (int i = 0; i < lottoNumbers.Length; i++)
- {
- if (lottoNumbers[i] == playerInput)
- {
- lottoNumbers[i] = -1;
- return 1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement