Click to See Complete Forum and Search --> : Array in Class


gamer1127
August 17th, 2009, 07:43 PM
Hello.

I am creating a simple program that will allow the user to enter 6 random numbers then after that a Random() class will generate 6 random numbers then verify if the random numbers generated matches the numbers entered by the user. It's like a computeruzed version of a lottery system.

Now, I'm thinking of storing the numbers that the user has entered in an array and the random numbers generated by the Random() class in another array, then use the two arrays to check if the numbers match or not.

I created a class for the numbers entered by the user and his other information e.g name, age. Then I also created a class for the random number generator.

Now, I just want to know how will i store the numbers entered by the user and the random numbers into the array? Also how will i force the random class to just generate up to 6 numbers and keep it from generating the same number again? May I know how will I declare the two arrays in the class?

rliq
August 17th, 2009, 09:56 PM
Using an Array is fine. You may find that sorting the Arrays before comparing them with each other helps.

As far as not having the same number generated twice... After generating a Random number, check if it is already in the Array. If it is, generate another one.

Declare two arrays in a class like this:


public class Lottery
{
private Int32[] _result = new Int32[6];
private Int32[] _guess = new Int32[6];
...
}