SHARE
TWEET

Untitled

a guest Nov 20th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. namespace lottery_game
  4. {
  5.     class Program
  6.     {
  7.  
  8.         static int[] userNumbers = new int[4];
  9.         static int[] lotteryNumbers = new int[4];
  10.         static int unConvertedDays = 0;
  11.         static int convertedDays = 0;
  12.         static int convertedMonths = 0;
  13.         static int convertedYears = 0;
  14.         static void Main(string[] args)
  15.         {
  16.  
  17.  
  18.             Console.WriteLine("Welcome to the lottery game. This will calculate how much time it will take for you to win the lottery exactly 100 times! Please choose 4 numbers from 0 to 100.");
  19.  
  20.             try
  21.             {
  22.                 userNumbers = GetAllNumbersFromPlayer();
  23.             }
  24.             catch (System.Exception)
  25.             {
  26.                 Console.WriteLine("Invalid, try again.");
  27.             }
  28.  
  29.             Console.WriteLine(String.Format("Thank you for inputting the numbers. The time it takes for you to win the lottery is {0} days or {1} year(s), {2} month(s), and {3} days.", unConvertedDays, convertedYears, convertedMonths, convertedDays));
  30.         }
  31.  
  32.         public static int[] GetAllNumbersFromPlayer()
  33.         {
  34.             int[] userNumbers = new int[4];
  35.  
  36.             userNumbers[0] = GetNumberFromPlayer();
  37.             userNumbers[1] = GetNumberFromPlayer();
  38.             userNumbers[2] = GetNumberFromPlayer();
  39.             userNumbers[3] = GetNumberFromPlayer();
  40.             Array.Sort(userNumbers);
  41.  
  42.             return userNumbers;
  43.         }
  44.  
  45.         public static int GetNumberFromPlayer()
  46.         {
  47.             int userNumber = Convert.ToInt32(Console.ReadLine());
  48.             bool verified = false;
  49.             while (verified == false)
  50.             {
  51.  
  52.                 if (
  53.                       userNumber > 100 || userNumber < 0)
  54.                 {
  55.                     throw new System.Exception("Invalid number, please try again.");
  56.                 }
  57.                 else
  58.                 {
  59.                     verified = true;
  60.                 }
  61.             }
  62.             return userNumber;
  63.         }
  64.  
  65.         public static int GetLotteryNumber()
  66.         {
  67.             Random rnd = new Random();
  68.             int lotteryNumber = rnd.Next(1, 101);
  69.  
  70.             return lotteryNumber;
  71.         }
  72.  
  73.         public static int[] GetAllLotteryNumbers()
  74.         {
  75.             int[] lotteryNumbers = new int[4];
  76.             lotteryNumbers[0] = GetLotteryNumber();
  77.             lotteryNumbers[1] = GetLotteryNumber();
  78.             lotteryNumbers[2] = GetLotteryNumber();
  79.             lotteryNumbers[3] = GetLotteryNumber();
  80.             Array.Sort(lotteryNumbers);
  81.  
  82.             return lotteryNumbers;
  83.         }
  84.  
  85.         public static int AmountOfDaysCalculated()
  86.         {
  87.  
  88.  
  89.             int points = 0;
  90.  
  91.             while (points < 100)
  92.             {
  93.                 GetAllLotteryNumbers();
  94.                
  95.                 unConvertedDays += 7;
  96.  
  97.                 if (lotteryNumbers == userNumbers)
  98.  
  99.                 {
  100.                     points++;
  101.                 }
  102.  
  103.             }
  104.             return unConvertedDays;
  105.         }
  106.  
  107.         public static void ConvertDays()
  108.         {
  109.             convertedDays = unConvertedDays;
  110.  
  111.             while (convertedDays > 365)
  112.             {
  113.                 convertedDays -= 365;
  114.                 convertedYears++;
  115.             }
  116.  
  117.             while (convertedDays > 30)
  118.             {
  119.                 convertedDays -= 30;
  120.                 convertedMonths++;
  121.             }
  122.  
  123.         }
  124.     }
  125. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top