Advertisement
Guest User

Untitled

a guest
May 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Lottokupon
  7. {
  8.     class Program
  9.     {
  10.         public static Random rnd = new Random();
  11.         public static int favoritNum = 0;
  12.  
  13.         static void Main(string[] args)
  14.         {
  15.             Console.WriteLine("Indtast nu dit favorit tal!");
  16.  
  17.             int favoritNum = int.Parse(Console.ReadLine());
  18.  
  19.             Console.WriteLine("Hvor mange rækker ønsker du på din lotto kupon?");
  20.  
  21.             int reakker = int.Parse(Console.ReadLine());
  22.  
  23.  
  24.             Console.WriteLine("Du har valgt købe {0} rækker på din lotto kupon", reakker);
  25.  
  26.             for (int i = 1; i <= reakker; i++)
  27.             {
  28.                 Console.Write("Række {0}: ", i);
  29.  
  30.                 RandomNum();
  31.  
  32.                 Console.Write("\n");
  33.             }
  34.  
  35.             Console.ReadKey();
  36.  
  37.         }
  38.  
  39.         //Her udregner vi vores random nummer, og tjekker om det er blevet udregnet 1 gang i forvejen.
  40.         public static void RandomNum()
  41.         {
  42.             List<int> list = new List<int>();
  43.  
  44.             while (list.Count < 7)
  45.             {
  46.                 int randnum = rnd.Next(1, 37);
  47.  
  48.                 if (!list.Contains(favoritNum))
  49.                 {
  50.                     list.Add(favoritNum);
  51.                 }
  52.  
  53.                 else if (!list.Contains(randnum))
  54.                 {
  55.                     list.Add(randnum);
  56.  
  57.                     if (randnum > 9)
  58.                     {
  59.                         Console.Write(randnum + " ");
  60.                     }
  61.                     else
  62.                     {
  63.                         Console.Write("0" + randnum + " ");
  64.                     }
  65.                 }
  66.                 else
  67.                 {
  68.  
  69.                 }
  70.  
  71.             }
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement