MuffinMonster

Class Task 53#

Feb 28th, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Console.WriteLine("Hey! Lets fill a lotto ticket!!!");
  13.             Loto file = new Loto();
  14.             int[,] ticket = file.GetTicket();
  15.             Console.WriteLine("Click enter to get your ticket");
  16.             Console.ReadLine();
  17.             Console.Clear();
  18.             for (int i = 0; i < ticket.GetLength(0); i++)
  19.             {
  20.                 for (int j = 0; j < ticket.GetLength(1); j++)
  21.                 {
  22.                     Console.Write(ticket[i, j] + " ");
  23.                 }
  24.                 Console.WriteLine();
  25.             }
  26.             Console.WriteLine("Click any key to find if you won any numbers:");
  27.             Console.ReadKey();
  28.             Console.WriteLine("The winning numbers are: ");
  29.             int[] win = file.GetWinners();
  30.             for (int i = 0;i < win.Length; i++)
  31.             {
  32.                 Console.Write(win[i] + " ");
  33.             }
  34.             Console.WriteLine();
  35.             int x = file.DidIwin();
  36.             Console.WriteLine("You guessed " + x + " right numbers (with a doubling with powerful one) ");
  37.             Console.WriteLine("You won " + (x * 100) + "$ - Congratulations!");
  38.             Console.ReadLine();
  39.  
  40.         }
  41.     }
  42. }
  43.  
  44. ///////////////////
  45.  
  46. using System;
  47. using System.Collections.Generic;
  48. using System.Linq;
  49. using System.Text;
  50.  
  51. namespace ConsoleApplication1
  52. {
  53.     class Loto
  54.     {
  55.         private int[,] ticket;
  56.         private int[] winners;
  57.         public Loto()
  58.         {
  59.             this.ticket = new int[12, 7];
  60.             this.winners = new int[7];
  61.             Random R = new Random();
  62.             int j, i;
  63.             for (i = 0; i < winners.Length - 1; i++)
  64.             {
  65.                 winners[i] = R.Next(1, 50);
  66.             }
  67.             winners[winners.Length - 1] = R.Next(1, 10);
  68.             for (i = 0; i < ticket.GetLength(0); i++)
  69.             {
  70.                 for (j = 0; j < ticket.GetLength(1) - 1; j++)
  71.                 {
  72.                     ticket[i, j] = R.Next(1, 50);
  73.                 }
  74.                 ticket[i, j] = R.Next(1, 10);
  75.             }
  76.         }
  77.         public int[,] GetTicket()
  78.         {
  79.             return this.ticket;
  80.         }
  81.         public int[] GetWinners()
  82.         {
  83.             return this.winners;
  84.         }
  85.         public int DidIwin()
  86.         {
  87.             int sum = 0;
  88.             int counter;
  89.             bool powerful = true;
  90.             int i, j, k;
  91.             for (i = 0; i < this.ticket.GetLength(0); i++)
  92.             {
  93.                 counter = 0;
  94.                 for (j = 0; j < this.ticket.GetLength(1); j++)
  95.                 {
  96.                     for (k = 0; k < this.winners.Length - 1; k++)
  97.                     {
  98.                         if (this.winners[k] == this.ticket[i, j])
  99.                         {
  100.                             counter++;
  101.                         }
  102.                     }
  103.                     if (counter > 2)
  104.                     {
  105.                         if (this.winners[winners.Length - 1] == this.ticket[i, j])
  106.                         {
  107.                             counter *= 2;
  108.                         }
  109.                         sum += counter;
  110.                     }
  111.                 }
  112.             }
  113.             return sum;
  114.         }
  115.     }
  116. }
Add Comment
Please, Sign In to add comment