Lottó program
This commit is contained in:
3
Lotto/Lotto.slnx
Normal file
3
Lotto/Lotto.slnx
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<Solution>
|
||||||
|
<Project Path="Lotto/Lotto.csproj" />
|
||||||
|
</Solution>
|
||||||
10
Lotto/Lotto/Lotto.csproj
Normal file
10
Lotto/Lotto/Lotto.csproj
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
114
Lotto/Lotto/Program.cs
Normal file
114
Lotto/Lotto/Program.cs
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user