mardi 6 novembre 2018

c# Lottery looping program with Visual Studio

I am currently trying to figure out how to create a program within Visual Studio, that matches 3 numbers given in a textbox with 3 random generated numbers in a listbox. I am having trouble figuring out how to write a WHILE looping statement that'll allow for my listbox to randomly generate 3 numbers at a time and continue if there is no match, but breaks if there is a match, with a max of 1000 attempts. I am a bit lost on how to do this. Thank you for your help.

        private void LuckyButton_Click(object sender, EventArgs e)
    {
        Random RandomNumber = new Random();
        string newLine = Environment.NewLine;
        int Winning1 = 0;
        int Winning2 = 0;
        int Winning3 = 0;
        int numbers = RandomNumber.Next(0, 1001);

        int.TryParse(WinningNumber1.Text, out Winning1);
        int.TryParse(WinningNumber2.Text, out Winning2);
        int.TryParse(WinningNumber3.Text, out Winning3);


        if (Winning1 <= 0 || Winning2 <= 0 || Winning3 <= 0)
        {
            MessageBox.Show("Enter a number!");
            return;
        }

        while (numbers <= 1000)
        {
            numbers = RandomNumber.Next(0, 1001);
            numbers = numbers + 1;
        }

    }




Aucun commentaire:

Enregistrer un commentaire