# TRYING to display even numbers of 100 random numbers between 0 & 1

Page 1 of 1

## 11 Replies - 2846 Views - Last Post: 28 March 2012 - 10:18 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=272748&amp;s=4274e7513c27a6e97dcac2de582f6542&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 snafu117

Reputation: 0
• Posts: 9
• Joined: 21-March 12

# TRYING to display even numbers of 100 random numbers between 0 & 1

Posted 27 March 2012 - 12:19 PM

```using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace randomNumber
{
class Program
{
static void Main(string[] args)
{
Random numb = new Random();
int n = numb.Next(1000);
string r;

string results = "";
int counter = 0;

do
{
n = numb.Next(1000);
r = Convert.ToString(n);
counter++;
results += counter + ")\t" + r + "\t";
}

for (int i=2; i <= 1000; i=i+2) //THIS IS THE PART OF THE CODE THATS SUPPOSED TO DISPLAY THE EVEN
Console.WriteLine(i);           // NUMBERS OF THE 100 RANDOMS, BUT I KEEP GETTING ERROrs
// what am i doing wrong?

while (counter < 100&&n<1000);

MessageBox.Show(results, "Random Numbers" , MessageBoxButtons.OK);

}
}
}
```

Is This A Good Question/Topic? 0

## Replies To: TRYING to display even numbers of 100 random numbers between 0 & 1

### #2 modi123_1

• Suitor #2

Reputation: 14158
• Posts: 56,748
• Joined: 12-June 08

## Re: TRYING to display even numbers of 100 random numbers between 0 & 1

Posted 27 March 2012 - 12:22 PM

Quote

//THIS IS THE PART OF THE CODE THATS SUPPOSED TO DISPLAY THE EVEN
// NUMBERS OF THE 100 RANDOMS, BUT I KEEP GETTING ERROrs
// what am i doing wrong?

### #3 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5104
• Posts: 9,283
• Joined: 08-June 10

## Re: TRYING to display even numbers of 100 random numbers between 0 & 1

Posted 27 March 2012 - 12:27 PM

"between 0 & 1"

...there are no numbers between 0 and 1.

### #4 Ryano121

• D.I.C Lover

Reputation: 1461
• Posts: 3,289
• Joined: 30-January 11

## Re: TRYING to display even numbers of 100 random numbers between 0 & 1

Posted 27 March 2012 - 12:38 PM

Unless they mean 100 random decimal numbers between 0 and 1?

In which case you want to be using the .NextDouble method instead of .Next.

But then again they seem to be wanting to find all the even numbers, in which case using decimals wouldn't work.

This post has been edited by Ryano121: 27 March 2012 - 12:40 PM

### #5 modi123_1

• Suitor #2

Reputation: 14158
• Posts: 56,748
• Joined: 12-June 08

## Re: TRYING to display even numbers of 100 random numbers between 0 & 1

Posted 27 March 2012 - 12:42 PM

Bah.. there are plenty of numbers between 0 and 1.. not many of them are WHOLE numbers but they are numbers regardless of their handicaps..

### #6 snafu117

Reputation: 0
• Posts: 9
• Joined: 21-March 12

## Re: TRYING to display even numbers of 100 random numbers between 0 & 1

Posted 27 March 2012 - 02:23 PM

they are not decimals, they are integers. the code finds 100 random integers between 0 and 1000, this part of the code is done, now im trying to sort the even numbers into a separate column in the message box that appears after i run the code, i keep getting syntax errors, not exactly sure what the syntax errors are but there are an error for the for and while

### #7 Ryano121

• D.I.C Lover

Reputation: 1461
• Posts: 3,289
• Joined: 30-January 11

## Re: TRYING to display even numbers of 100 random numbers between 0 & 1

Posted 27 March 2012 - 02:28 PM

What do you mean you don't know what the error messages are?

Copy and paste the errors you get when you try to compile in Visual Studio and post them here.

### #8 snafu117

Reputation: 0
• Posts: 9
• Joined: 21-March 12

## Re: TRYING to display even numbers of 100 random numbers between 0 & 1

Posted 27 March 2012 - 02:37 PM

"The name 'MessageBox' does not exist in the current context"

"The name 'MessageBoxButtons' does not exist in the currentcontext"

looks like the errors for "for" and "while" have went away. anyway those are the messages that appear now.

### #9 tlhIn`toq

• Xamarin Cert. Dev.

Reputation: 6535
• Posts: 14,450
• Joined: 02-June 10

## Re: TRYING to display even numbers of 100 random numbers between 0 & 1

Posted 28 March 2012 - 06:37 AM

Start by cleaning up your code.

What's with lines 33 and 34 sitting between your DO and WHILE statements? If you frak up all the syntax and completely confuse the compiler you will get errors where you think you shouldn't.

Since you are using a random number to start with, just adding 2 to it doesn't guarantee its even. Use the modulus function to determin if it is even

```x = myRandom.NextRandom();
if (x%2 == 0) // then its even
```

### #10 negligible

• D.I.C Regular

Reputation: 62
• Posts: 302
• Joined: 02-December 10

## Re: TRYING to display even numbers of 100 random numbers between 0 & 1

Posted 28 March 2012 - 08:01 AM

snafu117, on 27 March 2012 - 09:37 PM, said:

"The name 'MessageBox' does not exist in the current context"

Most of the time this error means you are missing a Using directive.

Right click on the red underlined "MessageBox" in your code, then you'll seeing an option called "Resolve" above refactor which should fill in the missing directive for you.

The other common one is trying to use something out of it's scope, for example trying to use a variable you declared in method in another separate method. (Instead of declaring it at class level so you can use it in both)

This post has been edited by negligible: 28 March 2012 - 08:04 AM

### #11 tlhIn`toq

• Xamarin Cert. Dev.

Reputation: 6535
• Posts: 14,450
• Joined: 02-June 10

## Re: TRYING to display even numbers of 100 random numbers between 0 & 1

Posted 28 March 2012 - 08:21 AM

negligible, on 28 March 2012 - 09:01 AM, said:

snafu117, on 27 March 2012 - 09:37 PM, said:

"The name 'MessageBox' does not exist in the current context"

Most of the time this error means you are missing a Using directive.

There is no need for guessing about that. The OP does have the proper using directive.
05 using System.Windows.Forms;

Mind you he's trying to call it from a console app. I'm not sure that's even possible. Hmmm... Something to play with

Like I said... Fix your code. You can't have statements between the Do{} and While blocks.
Visual Studio is even telling you what it expected. Just follow the tooltips.

Yep, if you fix the stuff its telling you to fix, you are indeed able to use a MessageBox from a console app.

### #12 snafu117

Reputation: 0
• Posts: 9
• Joined: 21-March 12

## Re: TRYING to display even numbers of 100 random numbers between 0 & 1

Posted 28 March 2012 - 10:18 AM

thank you all :] i think i have it figured out! ill be sure to + you guys! thanks a lot!