This is for a school project: write a GUI application that will generate multiple 3 digit numbers and count how many times each 3 digit number appears. To make the program more useful, provide the following:

A label that displays the 10 most common 3 digit numbers and the number of times it appeared
A label that displays the 10 least common 3 digit numbers and the number of times it appeared
A button that, when clicked, generates 10,000 random, 3 digit numbers and then populates the two labels mentioned above
NOTE: For each subsequent click of the button, new 3 digit values are generated, however the old counts remain.

I thought I had a good start going here, but when testing it just seems to run endlessly. Here is what I have found out. If I take the arrayFill() out of the form1() the form comes up and hangs when I hit the generate 10,000 random numbers. With the arrayFill() in the form1() the form never loads and I just get an hour glass. I tried just for testing to change the array to a single dimensional array and just trying to fill the 10,000 number to an array of 10,000 and put in a line to say done in the maxLbl label and just got an hour glass again. Just want to see if you guys see issues in my code? (I'm sure there are plenty of holes, :-) )

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _0804A_IT466_DavidSchmidtII_Unit3_Lottery
{
    public partial class Form1 : Form
    {
        int randomNumber = -1;
        int[,] lotteryNumbers = new int [1000,2];
        int[,] maxNumbers = new int[10, 2];
        int[,] minNumbers = new int[10, 2];


        System.Random RandNum = new System.Random();

        public Form1()
        {
            InitializeComponent();
            fillArray();
        }

        private void genRandNmbrBtn_Click(object sender, EventArgs e)
        {
            for (int j = 0; j < 10000; )
            {
                randomNumber = RandNum.Next(1000);
                for (int i = 0; i < 1000; )
                {
                    if (lotteryNumbers[i,0] == randomNumber)
                        lotteryNumbers[i,1]++;
                }
            }
            maxNumber();

        }

        private void fillArray()
        {
            for (int i = 0; i < 1000; )
            {
                lotteryNumbers[i, 0] = i;
            }
        }

        public void maxNumber()
        {
            for (int j = 0; j < 1000; )
            {
                if (lotteryNumbers[j,1] > maxNumbers[0,1])
                {
                    maxNumbers[9,1] = maxNumbers[8,1];
                    maxNumbers[8,1] = maxNumbers[7,1];
                    maxNumbers[7,1] = maxNumbers[6,1];
                    maxNumbers[6,1] = maxNumbers[5,1];
                    maxNumbers[5,1] = maxNumbers[4,1];
                    maxNumbers[4,1] = maxNumbers[3,1];
                    maxNumbers[3,1] = maxNumbers[2,1];
                    maxNumbers[2,1] = maxNumbers[1,1];
                    maxNumbers[1,1] = maxNumbers[0,1];
                    maxNumbers[0,1] = lotteryNumbers[j,1];
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[1, 1])
                {
                    maxNumbers[9, 1] = maxNumbers[8, 1];
                    maxNumbers[8, 1] = maxNumbers[7, 1];
                    maxNumbers[7, 1] = maxNumbers[6, 1];
                    maxNumbers[6, 1] = maxNumbers[5, 1];
                    maxNumbers[5, 1] = maxNumbers[4, 1];
                    maxNumbers[4, 1] = maxNumbers[3, 1];
                    maxNumbers[3, 1] = maxNumbers[2, 1];
                    maxNumbers[2, 1] = maxNumbers[1, 1];
                    maxNumbers[1, 1] = lotteryNumbers[j, 1];
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[2, 1])
                {
                    maxNumbers[9, 1] = maxNumbers[8, 1];
                    maxNumbers[8, 1] = maxNumbers[7, 1];
                    maxNumbers[7, 1] = maxNumbers[6, 1];
                    maxNumbers[6, 1] = maxNumbers[5, 1];
                    maxNumbers[5, 1] = maxNumbers[4, 1];
                    maxNumbers[4, 1] = maxNumbers[3, 1];
                    maxNumbers[3, 1] = maxNumbers[2, 1];
                    maxNumbers[2, 1] = maxNumbers[j, 1];
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[3, 1])
                {
                    maxNumbers[9, 1] = maxNumbers[8, 1];
                    maxNumbers[8, 1] = maxNumbers[7, 1];
                    maxNumbers[7, 1] = maxNumbers[6, 1];
                    maxNumbers[6, 1] = maxNumbers[5, 1];
                    maxNumbers[5, 1] = maxNumbers[4, 1];
                    maxNumbers[4, 1] = maxNumbers[3, 1];
                    maxNumbers[3, 1] = maxNumbers[j, 1];
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[4, 1])
                {
                    maxNumbers[9, 1] = maxNumbers[8, 1];
                    maxNumbers[8, 1] = maxNumbers[7, 1];
                    maxNumbers[7, 1] = maxNumbers[6, 1];
                    maxNumbers[6, 1] = maxNumbers[5, 1];
                    maxNumbers[5, 1] = maxNumbers[4, 1];
                    maxNumbers[4, 1] = maxNumbers[j, 1];
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[5, 1])
                {
                    maxNumbers[9, 1] = maxNumbers[8, 1];
                    maxNumbers[8, 1] = maxNumbers[7, 1];
                    maxNumbers[7, 1] = maxNumbers[6, 1];
                    maxNumbers[6, 1] = maxNumbers[5, 1];
                    maxNumbers[5, 1] = maxNumbers[j, 1];
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[6, 1])
                {
                    maxNumbers[9, 1] = maxNumbers[8, 1];
                    maxNumbers[8, 1] = maxNumbers[7, 1];
                    maxNumbers[7, 1] = maxNumbers[6, 1];
                    maxNumbers[6, 1] = maxNumbers[j, 1];
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[7, 1])
                {
                    maxNumbers[9, 1] = maxNumbers[8, 1];
                    maxNumbers[8, 1] = maxNumbers[7, 1];
                    maxNumbers[7, 1] = maxNumbers[j, 1];
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[8, 1])
                {
                    maxNumbers[9, 1] = maxNumbers[8, 1];
                    maxNumbers[8, 1] = maxNumbers[j, 1];
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[9, 1])
                {
                    maxNumbers[9, 1] = maxNumbers[j, 1];
                }
            }

            for (int i = 0; i < 10; )
            {
                maxLbl.Text = Convert.ToString(maxNumbers[i,i]);
            }
        }
    }
}

It hangs coz you told it to

for (int i = 0; i < 1000; )
                {
                    if (lotteryNumbers[i,0] == randomNumber)
                        lotteryNumbers[i,1]++;
                }

Look carefully at your loop

Comments
Dead acurate

Boy don't I feel stupid, rookie mistake! I can't believe I did that and this not being my first programming class, lol. I guess sometimes the simple is the most over looked. I may be back as it does start now and crashes, but that is not what brought me here in the first place, just what might bring me back. :-)

Comments
you have the right spirit

Its always easier to spot a mistake in someone elses work.

As a kid my parents used to get so frustrated with me, Id write stuff but Im dyslexic and my brain thinks a lot faster than it writes, As as a result Id read what my brain meant to write, not what was on the paper, and Id miss out huge chunks and not see it!

At least if it crashes you should have a good idea why :)

This is for a school project: write a GUI application that will generate multiple 3 digit numbers and count how many times each 3 digit number appears. To make the program more useful, provide the following:

A label that displays the 10 most common 3 digit numbers and the number of times it appeared
A label that displays the 10 least common 3 digit numbers and the number of times it appeared
A button that, when clicked, generates 10,000 random, 3 digit numbers and then populates the two labels mentioned above
NOTE: For each subsequent click of the button, new 3 digit values are generated, however the old counts remain.

This almost works the way it should for the maximum only index 0 and 1 are ending up with the same value. The minimum is returning 0 0 for all indexes. Now I would think the > 0 would eliminate all 0 values?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _0804A_IT466_DavidSchmidtII_Unit3_Lottery
{
    public partial class Form1 : Form
    {
        int randomNumber = -1;
        int[,] lotteryNumbers = new int [1000, 2];
        int[,] maxNumbers = new int[10, 2];
        int[,] minNumbers = new int[10, 2];


        System.Random RandNum = new System.Random();

        public Form1()
        {
            InitializeComponent();
            fillArray();
        }

        private void genRandNmbrBtn_Click(object sender, EventArgs e)
        {
            maxLbl.Text = "";
            for (int j = 0; j < 10000; ++j)
            {
                randomNumber = RandNum.Next(1000);
                for (int i = 0; i < 1000; ++i)
                {
                    if (lotteryNumbers[i, 0] == randomNumber)
                        lotteryNumbers[i, 1]++;
                }
            }

            maxNumber();
            minNumber();
        }

        private void fillArray()
        {
            for (int i = 0; i < 1000; ++i)
            {
                lotteryNumbers[i, 0] = i;
            }

            for (int i = 0; i < 10; ++i)
            {
                minNumbers[i, 1] = 5000;
            }
        }

        public void maxNumber()
        {
            for (int j = 0; j < 1000; ++j)
            {
                if (lotteryNumbers[j, 1] > maxNumbers[0, 1])
                {
                    for (int i = 9; i > 0; --i)
                    {
                        maxNumbers[i, 1] = maxNumbers[i - 1, 1];
                        maxNumbers[i, 0] = maxNumbers[i - 1, 0];
                        maxNumbers[0, 1] = lotteryNumbers[j, 1];
                        maxNumbers[0, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[1, 1])
                {
                    for (int i = 9; i > 1; --i)
                    {
                        maxNumbers[i, 1] = maxNumbers[i - 1, 1];
                        maxNumbers[i, 0] = maxNumbers[i - 1, 0];
                        maxNumbers[1, 1] = lotteryNumbers[j, 1];
                        maxNumbers[1, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[2, 1])
                {
                    for (int i = 9; i > 2; --i)
                    {
                        maxNumbers[i, 1] = maxNumbers[i - 1, 1];
                        maxNumbers[i, 0] = maxNumbers[i - 1, 0];
                        maxNumbers[2, 1] = lotteryNumbers[j, 1];
                        maxNumbers[2, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[3, 1])
                {
                    for (int i = 9; i > 3; --i)
                    {
                        maxNumbers[i, 1] = maxNumbers[i - 1, 1];
                        maxNumbers[i, 0] = maxNumbers[i - 1, 0];
                        maxNumbers[3, 1] = lotteryNumbers[j, 1];
                        maxNumbers[3, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[4, 1])
                {
                    for (int i = 9; i > 4; --i)
                    {
                        maxNumbers[i, 1] = maxNumbers[i - 1, 1];
                        maxNumbers[i, 0] = maxNumbers[i - 1, 0];
                        maxNumbers[4, 1] = lotteryNumbers[j, 1];
                        maxNumbers[4, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[5, 1])
                {
                    for (int i = 9; i > 5; --i)
                    {
                        maxNumbers[i, 1] = maxNumbers[i - 1, 1];
                        maxNumbers[i, 0] = maxNumbers[i - 1, 0];
                        maxNumbers[5, 1] = lotteryNumbers[j, 1];
                        maxNumbers[5, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[6, 1])
                {
                    for (int i = 9; i > 6; --i)
                    {
                        maxNumbers[i, 1] = maxNumbers[i - 1, 1];
                        maxNumbers[i, 0] = maxNumbers[i - 1, 0];
                        maxNumbers[6, 1] = lotteryNumbers[j, 1];
                        maxNumbers[6, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[7, 1])
                {
                    for (int i = 9; i > 7; --i)
                    {
                        maxNumbers[i, 1] = maxNumbers[i - 1, 1];
                        maxNumbers[i, 0] = maxNumbers[i - 1, 0];
                        maxNumbers[7, 1] = lotteryNumbers[j, 1];
                        maxNumbers[7, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[8, 1])
                {
                    for (int i = 9; i > 8; --i)
                    {
                        maxNumbers[i, 1] = maxNumbers[i - 1, 1];
                        maxNumbers[i, 0] = maxNumbers[i - 1, 0];
                        maxNumbers[8, 1] = lotteryNumbers[j, 1];
                        maxNumbers[8, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > maxNumbers[9, 1])
                {
                        maxNumbers[9, 1] = lotteryNumbers[j, 1];
                        maxNumbers[9, 0] = lotteryNumbers[j, 0];
                }
            }

            for (int i = 0; i < 10; ++i)
            {
                maxLbl.Text += maxNumbers[i, 0].ToString("000") + "     " + Convert.ToString(maxNumbers[i, 1]) + "\n";
            }
        }

        public void minNumber()
        {
            for (int j = 0; j < 1000; ++j)
            {
                if (lotteryNumbers[j, 1] > 0 & lotteryNumbers[j, 1] < minNumbers[0, 1])
                {
                    for (int i = 9; i > 0; --i)
                    {
                        minNumbers[i, 1] = minNumbers[i - 1, 1];
                        minNumbers[i, 0] = minNumbers[i - 1, 0];
                        minNumbers[0, 1] = lotteryNumbers[j, 1];
                        minNumbers[0, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > 0 & lotteryNumbers[j, 1] < minNumbers[1, 1])
                {
                    for (int i = 9; i > 1; --i)
                    {
                        minNumbers[i, 1] = minNumbers[i - 1, 1];
                        minNumbers[i, 0] = minNumbers[i - 1, 0];
                        minNumbers[1, 1] = lotteryNumbers[j, 1];
                        minNumbers[1, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > 0 & lotteryNumbers[j, 1] < minNumbers[2, 1])
                {
                    for (int i = 9; i > 2; --i)
                    {
                        minNumbers[i, 1] = minNumbers[i - 1, 1];
                        minNumbers[i, 0] = minNumbers[i - 1, 0];
                        minNumbers[2, 1] = lotteryNumbers[j, 1];
                        minNumbers[2, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > 0 & lotteryNumbers[j, 1] < minNumbers[3, 1])
                {
                    for (int i = 9; i > 3; --i)
                    {
                        minNumbers[i, 1] = minNumbers[i - 1, 1];
                        minNumbers[i, 0] = minNumbers[i - 1, 0];
                        minNumbers[3, 1] = lotteryNumbers[j, 1];
                        minNumbers[3, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > 0 & lotteryNumbers[j, 1] < minNumbers[4, 1])
                {
                    for (int i = 9; i > 4; --i)
                    {
                        minNumbers[i, 1] = minNumbers[i - 1, 1];
                        minNumbers[i, 0] = minNumbers[i - 1, 0];
                        minNumbers[4, 1] = lotteryNumbers[j, 1];
                        minNumbers[4, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > 0 & lotteryNumbers[j, 1] < minNumbers[5, 1])
                {
                    for (int i = 9; i > 5; --i)
                    {
                        minNumbers[i, 1] = minNumbers[i - 1, 1];
                        minNumbers[i, 0] = minNumbers[i - 1, 0];
                        minNumbers[5, 1] = lotteryNumbers[j, 1];
                        minNumbers[5, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > 0 & lotteryNumbers[j, 1] < minNumbers[6, 1])
                {
                    for (int i = 9; i > 6; --i)
                    {
                        minNumbers[i, 1] = minNumbers[i - 1, 1];
                        minNumbers[i, 0] = minNumbers[i - 1, 0];
                        minNumbers[6, 1] = lotteryNumbers[j, 1];
                        minNumbers[6, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > 0 & lotteryNumbers[j, 1] < minNumbers[7, 1])
                {
                    for (int i = 9; i > 7; --i)
                    {
                        minNumbers[i, 1] = minNumbers[i - 1, 1];
                        minNumbers[i, 0] = minNumbers[i - 1, 0];
                        minNumbers[7, 1] = lotteryNumbers[j, 1];
                        minNumbers[7, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > 0 & lotteryNumbers[j, 1] < minNumbers[8, 1])
                {
                    for (int i = 9; i > 8; --i)
                    {
                        minNumbers[i, 1] = minNumbers[i - 1, 1];
                        minNumbers[i, 0] = minNumbers[i - 1, 0];
                        minNumbers[8, 1] = lotteryNumbers[j, 1];
                        minNumbers[8, 0] = lotteryNumbers[j, 0];
                    }
                }
                else if (lotteryNumbers[j, 1] > 0 & lotteryNumbers[j, 1] < minNumbers[9, 1])
                {
                    minNumbers[9, 1] = lotteryNumbers[j, 1];
                    minNumbers[9, 0] = lotteryNumbers[j, 0];
                }
            }

            for (int i = 0; i < 10; ++i)
            {
                minLbl.Text += minNumbers[i, 0].ToString("000") + "     " + Convert.ToString(minNumbers[i, 1]) + "\n";
            }
        }
    }
}

Your min function still tests if the numbers are BIGGER than the ones you have.. You also probably would want to start at a high number and work down as 0 would always be the lowest number..

Doh! That is right I thought about that hours ago while working on the maximum method and forgot to address it. I was going to try and initialize it with larger values than the default 0. Thanks for reminding me, now just have to figure out why the double in the maximum method.

Thats why we coders invented a progress called debugging.. watch what it does step by step you'll find it then.

I added this to take care of the error you spotted LizR, thanks!

for (int i = 0; i < 10; ++i)
            {
                minNumbers[i, 1] = 5000;
            }

I notice now that first 8 index's double in pairs and the last two do not for both the max and the min. Onto something, just not sure what.

I streamlined the max and min methods but still getting duplicate data.

public void maxNumber()
        {
            for (int j = 0; j < 1000; ++j)
            {
                for (int i = 0; i < 10; ++i)
                {
                    if (lotteryNumbers[j, 1] > maxNumbers[i, 1])
                    {
                        for (int h = 9; h > i; --h)
                        {
                            maxNumbers[h, 1] = maxNumbers[h - 1, 1];
                            maxNumbers[h, 0] = maxNumbers[h - 1, 0];
                            maxNumbers[i, 1] = lotteryNumbers[j, 1];
                            maxNumbers[i, 0] = lotteryNumbers[j, 0];
                        }
                        i = 10;
                    }
                }
            }

            for (int i = 0; i < 10; ++i)
            {
                maxLbl.Text += maxNumbers[i, 0].ToString("000") + "     " + Convert.ToString(maxNumbers[i, 1]) + "\n";
            }
        }

        public void minNumber()
        {
            for (int j = 0; j < 1000; ++j)
            {
                for (int i = 0; i < 10; ++i)
                {
                    if (lotteryNumbers[j, 1] > 0 & lotteryNumbers[j, 1] < minNumbers[i, 1])
                    {
                        for (int h = 9; h > i; --h)
                        {
                            minNumbers[h, 1] = minNumbers[h - 1, 1];
                            minNumbers[h, 0] = minNumbers[h - 1, 0];
                            minNumbers[i, 1] = lotteryNumbers[j, 1];
                            minNumbers[i, 0] = lotteryNumbers[j, 0];
                        }
                        i = 10;
                    }
                }
            }

            for (int i = 0; i < 10; ++i)
            {
                minLbl.Text += minNumbers[i, 0].ToString("000") + "     " + Convert.ToString(minNumbers[i, 1]) + "\n";
            }
        }

I think I found it, I'm using the counter from the for statements which of course are -1 by the time they hit the if, I'm really not thinking today!

Nope the counter produces the right values that wasn't it.

Figured it out!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _0804A_IT466_DavidSchmidtII_Unit3_Lottery
{
    public partial class Form1 : Form
    {
        int randomNumber = -1; // Variable to hold random generated number
        int[,] lotteryNumbers = new int [1000, 2]; // Array to hold numbers 000 - 999 and count occurance
        int[,] maxNumbers = new int[10, 2]; // Array to hold 10 most frequent numbers
        int[,] minNumbers = new int[10, 2]; // Array to hold l0 least frequent numbers


        System.Random RandNum = new System.Random();

        public Form1()
        {
            InitializeComponent();
            fillLotteryArray(); // Fill lottery number array minimum number array 
        }

        private void genRandNmbrBtn_Click(object sender, EventArgs e) // Generate random numbers and count frequency
        {
            fillMinNumbersArray();
            maxLbl.Text = ""; // Clear max label
            minLbl.Text = ""; // Clear min label
            for (int j = 0; j < 10000; ++j)
            {
                randomNumber = RandNum.Next(999); // Generate 10,000 random numbers
                for (int i = 0; i < 1000; ++i)
                {
                    if (lotteryNumbers[i, 0] == randomNumber) // Count frequency
                        lotteryNumbers[i, 1]++;
                }
            }
            
            maxNumber(); // Display maximum numbers
            minNumber(); // Display minimum numbers
        }

        private void fillLotteryArray() //Fill lottery number array with values 000 - 999
        {
            for (int i = 0; i < 1000; ++i)
            {
                lotteryNumbers[i, 0] = i;
            }
        }

        private void fillMinNumbersArray() //Fill minimum numbers array with value 5000
        {
            for (int i = 0; i < 10; ++i)
            {
                minNumbers[i, 1] = 5000;
            }
        }

        public void maxNumber() // Find 10 most frequent numbers
        {
            for (int j = 0; j < 1000; ++j) // Loop for all 1000 lottery numbers
            {
                for (int i = 0; i < 10; ++i) // Loop for the 10 maximum numbers
                {
                    if (lotteryNumbers[j, 1] > maxNumbers[i, 1]) // Check if there is a more fequent number than the one stored at each index
                    {
                        for (int h = 9; h > i; --h) // Starting with index 9, store previous index value until you reach the index that will store the new value 
                        {
                            maxNumbers[h, 1] = maxNumbers[h - 1, 1];
                            maxNumbers[h, 0] = maxNumbers[h - 1, 0];
                        }
                        maxNumbers[i, 1] = lotteryNumbers[j, 1]; // Store new values at slated index
                        maxNumbers[i, 0] = lotteryNumbers[j, 0];
                        i = 10;
                    }
                }
            }

            for (int i = 0; i < 10; ++i) // Display each number and its frequency
            {
                maxLbl.Text += maxNumbers[i, 0].ToString("000") + "     " + Convert.ToString(maxNumbers[i, 1]) + "\n";
            }
        }

        public void minNumber() // Find 10 least frequent numbers
        {
            for (int j = 0; j < 1000; ++j) // Loop for all 1000 lottery numbers
            {
                for (int i = 0; i < 10; ++i) // Loop for the 10 minimum numbers
                {
                    if (lotteryNumbers[j, 1] > 0 & lotteryNumbers[j, 1] < minNumbers[i, 1]) // Check if there is a less frequent number than the one stored at each index disregarding numbers that have not been drawn
                    {
                        for (int h = 9; h > i; --h) // Starting with index 9, store previous index value until you reach the index that will store the new value
                        {
                            minNumbers[h, 1] = minNumbers[h - 1, 1];
                            minNumbers[h, 0] = minNumbers[h - 1, 0];
                        }
                        minNumbers[i, 1] = lotteryNumbers[j, 1]; // Store new values at slated index
                        minNumbers[i, 0] = lotteryNumbers[j, 0];
                        i = 10;
                    }
                }
            }

            for (int i = 0; i < 10; ++i) // Display each number and its frequency
            {
                minLbl.Text += minNumbers[i, 0].ToString("000") + "     " + Convert.ToString(minNumbers[i, 1]) + "\n";
            }
        }
    }
}
This question has already been answered. Start a new discussion instead.