Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Somewhat Noob help... User insert array and random number function

SivySivy Member Posts: 1
alright a couple of problems, one of them is that I can't stop this 0 from appearing in my random number array.


[code] public override string ToString()
{
Console.Write("this is the array: ");
int i = 0 // I know that it prints out this 0 and i+1 doesn't work

while( i < boolSet.Length)
{
if (boolSet[i])
{
Console.Write(" " + i);

}
i++;
}
Console.WriteLine("");
return base.ToString();
}
[/code]


and I also need the array to check if the number is over the array max and min but it doesn't work, this is the constructor

[code]
public set(int[] intSet)
{
this.boolSet = new bool[101];


for (int i = 0; i < intSet.Length; )//doesn't stop the over number thing
{

if (!(intSet[i] < 0 && intSet[i] > 100))
{
boolSet[intSet[i]] = true;
i++;
}
else
{
Console.WriteLine("This doesn't work");
}
}
}[/code]

every array goes through it.

Also.

can't figure out the best way of making this into a function in Main
[code]
int[] randomSet = new int[101];
int[] randomSet1 = new int[101];
Random num = new Random();


for (int i = 0; i < 9; i++)
{

randomSet[i] = num.Next(0, 100);


}

for (int i = 0; i < 9; i++)
{

randomSet1[i] = num.Next(0, 100);


}


set rSet = new set(randomSet);
set rSet1 = new set(randomSet1);

[/code]

Comments

  • DataDinkDataDink Member Posts: 135
    So for your first question:
    What??? does the code below your question have anything to do with your question? is boolSet your array? - where does it come from? what are you trying to do, why are you using a "while" loop instead of a "for" loop? and what 0 are you talking about? If you don't want to print 0 then i=1;

    For your second question:
    for (int i = 0; i < intSet.Length; ) <--- is incomplete you really should be putting your incrementor in there.
    (intSet[i] < 0 && intSet[i] > 100) <--- will never ever be true


    For your third question:
    Are you trying to "make a function in Main" as in you want to create a delegate? - because "Main" is usually a method, and the only way to make a method inside of another method would be something like a delegate.
    Is the goal of this function to just create two new arrays of random numbers with 101 spaces but only 9 filled in? What part of this are you having trouble with?
Sign In or Register to comment.