Originally Posted by

**csmith03**
I tried that code, it just gave me an infinite loop where the random number was one every time. My task was to generate 100 random numbers on the interval [0,1] (so basically just 0 or 1) and print how many times the number one appears.

Thanks for the help!

you got your length 0 ... 99;

Code:

array[ number to indicate which element you want the value set inside of it ] = value;

use your counter to set the element = value

Code:

// seeings how you set t = 99, to counter act that you could do this
int t = 99 ,g = 0;
for ( t = 99; t > 0; t--)
{
myRandomNumberArray[g++] = (rand()%2);
}

or just start high ( 99 ) like you got it set and work your way down to zero 0

Code:

int t = 99;
for ( t = 99; t > 0; t--)
{
myRandomNumberArray[t] = (rand()%2);
}

but does that actually get you to 100 using 99?

run it two ways to see how this effects your count:

Code:

for ( t = 99; t > 0; t--)
array[ t ] = t;
// vs
for ( t = 99; t >= 0; t--)
array[ t ] = t;

then loop out its value to check your element count.

Code:

for ( t = 0; t < sizeof(array)/sizeof(array[0]); t++)
{
printf("t = %d number element is %d\n",t, array[t]);
}