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]);
}
}
}
}