I am a beginner at C# and I have a practice problem that I cannot figure out. This is what I need to do:

This is the code I have so far:

I am getting the exception regardless of what I put in. Please advice. Any help is appreciated. Thanks in advance!

- The program allows the users to specify how many random numbers (ranging from 1 to 100) to generate.
- The program generates the specified number random numbers.
- The program places an odd number in the oddNumListBox, and an even number to the evenNumListBox.
- The program calculates how many odd numbers and how many even numbers, and then display the counts respectively in the countOddNumLabel and countEvenNumLabel controls,
- You rare required to use at least one method in your code (in addition to even handlers).

This is the code I have so far:

private void generateButton_Click(object sender, EventArgs e) { try { int num; //ever or odd number int count; int countNumber = 0; //how many numbers //generate random number between 1 and 100 Random rand = new Random(); rand.Next(1, 100); for (count = 1; count <= 100; count++) { bool number = false; if (num % 2) { countNumber = int.Parse(oddNumListBox.Text); oddNumListBox.Items.Add("num"); } else { countNumber = int.Parse(evenNumListBox.Text); evenNumListBox.Items.Add("num"); } } } catch { MessageBox.Show("Enter a valid number"); } }

I am getting the exception regardless of what I put in. Please advice. Any help is appreciated. Thanks in advance!

#### Attachments

Last edited by a moderator: