mardi 7 novembre 2017

lottery vector with for loop without duplicates

The quest is solve the problem only with just these things that I (we) have learned. My program is working except i get duplicated random numbers. Please help how to do it, i'm trying since a half day:(

        int[] lotto = new int[6];
        Random rnd = new Random();
        int i;
        int max,min;            

        for (i=0; i<6; i++)
        {
            lotto[i] = rnd.Next(1, 46);
            Console.Write("{0} ", lotto[i]);
        }

        max=lotto[0];
        min=lotto[0];
        for (i=0; i<6; i++)
        {
            if (lotto[i]>max) max=lotto[i];
            if (lotto[i]<min) min=lotto[i];



        }

        Console.WriteLine("\nthe smallest num: {0} the biggest num: {1}", min, max);
        Console.ReadKey();




Aucun commentaire:

Enregistrer un commentaire