Files
asztali_12/Lotto/Lotto/Program.cs
Kovács Rudolf 74ee9eaffb Újrajátszás
2026-10-05 13:01:36 +02:00

100 lines
3.0 KiB
C#

namespace Lotto
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Lottó");
int hanySzam = 0;
int mennyiBol = 0;
int talalatok = 0;
Console.Write("Hány számot húzunk?");
hanySzam = Convert.ToInt32(Console.ReadLine());
Console.Write("Hány számból sorsolunk?");
mennyiBol = Convert.ToInt32(Console.ReadLine());
Random random = new Random();
int[] tippek = new int[hanySzam];
int[] nyeroszamok = new int[hanySzam];
//Tippek bekérése
//1 és hanySzam között kell lennie
//Nem lehet a tippek között
char valasz = 'n';
//ciklus kezdete
do
{
talalatok = 0;
for (int i = 0; i < hanySzam; i++)
{
Console.Write($"{i + 1}.tipp:");
int temp = Convert.ToInt32(Console.ReadLine());
//Ellenőrzés
while (temp < 1 || temp > mennyiBol || tippek.Contains(temp))
{
Console.Write($"Rossz tipp! Újra! {i + 1}.tipp:");
temp = Convert.ToInt32(Console.ReadLine());
}
tippek[i] = temp;
}
Array.Sort(tippek);
Tomblista(tippek);
//Nyerőszámok sorsolása
for (int i = 0; i < hanySzam; i++)
{
int temp = random.Next(1,mennyiBol+1);
while (nyeroszamok.Contains(temp))
{
temp = random.Next(1, mennyiBol + 1);
}
nyeroszamok[i] = temp;
}
Array.Sort(nyeroszamok);
Tomblista(nyeroszamok);
//Találatok meghatározása
for (int i = 0; i < tippek.Length; i++)
{
for (int j = 0; j < nyeroszamok.Length; j++)
{
if (tippek[i] == nyeroszamok[j])
{
talalatok++;
}
}
}
Console.WriteLine($"Találatok száma:{talalatok}");
Console.Write("Akar újra játszani? (i/n)");
valasz = Console.ReadKey().KeyChar;
Console.WriteLine();
}//ciklus vége
while (Char.ToLower(valasz)!='n');
//Fusson a program addig, amíg a megadott tippekkel el nem érünk 4 találatot.
//Írja ki a program, hogy ez hány évbe telt.
}
private static void Tomblista(int[] tomb)
{
for (int i = 0; i < tomb.Length; i++)
{
Console.Write(tomb[i] + " ");
}
Console.WriteLine();
}
}
}