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);
}
}
}
11 Replies - 925 Views - Last Post: 28 March 2012 - 10:18 AM
#1
TRYING to display even numbers of 100 random numbers between 0 & 1
Posted 27 March 2012 - 12:19 PM
Replies To: TRYING to display even numbers of 100 random numbers between 0 & 1
#2
Re: TRYING to display even numbers of 100 random numbers between 0 & 1
Posted 27 March 2012 - 12:22 PM
Quote
// NUMBERS OF THE 100 RANDOMS, BUT I KEEP GETTING ERROrs
// what am i doing wrong?
It's always good to share your errors your are getting..
#3
Re: TRYING to display even numbers of 100 random numbers between 0 & 1
Posted 27 March 2012 - 12:27 PM
...there are no numbers between 0 and 1.
#4
Re: TRYING to display even numbers of 100 random numbers between 0 & 1
Posted 27 March 2012 - 12:38 PM
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
Re: TRYING to display even numbers of 100 random numbers between 0 & 1
Posted 27 March 2012 - 12:42 PM
#6
Re: TRYING to display even numbers of 100 random numbers between 0 & 1
Posted 27 March 2012 - 02:23 PM
#7
Re: TRYING to display even numbers of 100 random numbers between 0 & 1
Posted 27 March 2012 - 02:28 PM
Copy and paste the errors you get when you try to compile in Visual Studio and post them here.
#8
Re: TRYING to display even numbers of 100 random numbers between 0 & 1
Posted 27 March 2012 - 02:37 PM
"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
Re: TRYING to display even numbers of 100 random numbers between 0 & 1
Posted 28 March 2012 - 06:37 AM
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
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:
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
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:
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
Re: TRYING to display even numbers of 100 random numbers between 0 & 1
Posted 28 March 2012 - 10:18 AM
|
|

New Topic/Question
Reply



MultiQuote








|