diff --git a/Lotto/Lotto.slnx b/Lotto/Lotto.slnx new file mode 100644 index 0000000..9ac40ec --- /dev/null +++ b/Lotto/Lotto.slnx @@ -0,0 +1,3 @@ + + + diff --git a/Lotto/Lotto/Lotto.csproj b/Lotto/Lotto/Lotto.csproj new file mode 100644 index 0000000..ed9781c --- /dev/null +++ b/Lotto/Lotto/Lotto.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/Lotto/Lotto/Program.cs b/Lotto/Lotto/Program.cs new file mode 100644 index 0000000..6a974b1 --- /dev/null +++ b/Lotto/Lotto/Program.cs @@ -0,0 +1,114 @@ +namespace Lotto +{ + internal class Program + { + static void Main(string[] args) + { + //Lottó program + Console.Write("Hány számot húzunk:"); + int hanySzam = Convert.ToInt32(Console.ReadLine()); + Console.Write("Hány számból húzunk:"); + int osszSzam = Convert.ToInt32(Console.ReadLine()); + + //Ellenőrzés! Az osszSzam változónak nagyobbnak kell lennie a hanySzam változónál! + + int[] tippek = new int[hanySzam]; + int[] nyeroSzamok = new int[hanySzam]; + + int talalat = 0; + + Random random = new Random(); + char valasz = 'n'; + + //A program kérdezze meg, hogy akarunk-e még egyszer játszani, ha igen akkor új játék, ha nem akkor kilépés + + do + { + + talalat = 0; + //tömbök nullázása! + + //Tippek bekérése + Tippeles(hanySzam, osszSzam, tippek); + + //Tippek megjelenítése + + //Rendezés + Array.Sort(tippek); + + TombLista(tippek); + + //Nyerőszámok sorsolása + Sorsolas(hanySzam, osszSzam, nyeroSzamok, random); + + Array.Sort(nyeroSzamok); + TombLista(nyeroSzamok); + + //Találatok számának meghatározása + + talalat = Talalatok(tippek, nyeroSzamok, talalat); + + Console.WriteLine($"Találatok száma:{talalat}"); + Console.Write("Akar még játszani? (i/n)"); + valasz = Console.ReadKey().KeyChar; + + } + while (valasz=='i'); + + + } + + private static int Talalatok(int[] tippek, int[] nyeroSzamok, int talalat) + { + for (int i = 0; i < tippek.Length; i++) + { + for (int j = 0; j < nyeroSzamok.Length; j++) + { + if (tippek[i] == nyeroSzamok[j]) + { + talalat++; + } + } + } + + return talalat; + } + + private static void Sorsolas(int hanySzam, int osszSzam, int[] nyeroSzamok, Random random) + { + for (int i = 0; i < hanySzam; i++) + { + int temp = random.Next(1, osszSzam + 1); + while (nyeroSzamok.Contains(temp)) + { + temp = random.Next(1, osszSzam + 1); + } + nyeroSzamok[i] = temp; + } + } + + private static void Tippeles(int hanySzam, int osszSzam, int[] tippek) + { + for (int i = 0; i < hanySzam; i++) + { + Console.Write($"Tipp {i + 1}.:"); + int temp = Convert.ToInt32(Console.ReadLine()); + while (temp < 1 || temp > osszSzam || tippek.Contains(temp)) + { + Console.Write($"Hibás! Add meg újra! Tipp {i + 1}.:"); + temp = Convert.ToInt32(Console.ReadLine()); + } + tippek[i] = temp; + } + } + + private static void TombLista(int[] tomb) + { + for (int i = 0; i < tomb.Length; i++) + { + Console.Write(tomb[i] + " "); + } + Console.WriteLine(); + } + } +}