だから私は宝くじを作っています。6 つのラッキー ナンバーを入力する必要があり、それらが宝くじの数字と同じ場合に当たります。
これが私のコードです:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OefeningExaam
{
class Program
{
static void Main(string[] args)
{
Random getal = new Random();
int[] lottotrekking = new int[6];
Console.WriteLine("Geef je geluksgetallen in <tussen 1 en 42>");
Console.WriteLine("Geef je eerste getal in");
int getal1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Geef je tweede getal in");
int getal2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Geef je derde getal in");
int getal3 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Geef je vierde getal in");
int getal4 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Geef je vijfde getal in");
int getal5 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Geef je zesde getal in");
int getal6 = Convert.ToInt32(Console.ReadLine());
while (getal1 != lottotrekking[0] || getal2 != lottotrekking[1] || getal3 != lottotrekking[2] || getal4 != lottotrekking[3] || getal5 != lottotrekking[4] || getal5 != lottotrekking[4] || getal6 != lottotrekking[5])
{
for (int i = 0; i < lottotrekking.Length; i++)
{
int cijfer = getal.Next(1, 43);
lottotrekking[i] = cijfer;
Console.WriteLine(lottotrekking[0] + "\t " + lottotrekking[1] + "\t " + lottotrekking[2] + "\t " + lottotrekking[3] + "\t " + lottotrekking[4] + "\t " + lottotrekking[5]);
}
}
if (getal1 == lottotrekking[0] && getal2 == lottotrekking[1] && getal3 == lottotrekking[2] && getal4 == lottotrekking[3] && getal5 == lottotrekking[4] && getal5 == lottotrekking[4] && getal6 == lottotrekking[5])
{
Console.WriteLine(lottotrekking[0] + " " + lottotrekking[1] + " " + lottotrekking[2] + " " + lottotrekking[3] + " " + lottotrekking[4] + " " + lottotrekking[5]);
}
Console.ReadLine();
}
}
}
問題は、プログラムが停止せずに進み続けることです。ラッキーナンバーと宝くじの数字が同じになった時点で停止するはずです。