Sorry to be a pain, but could you put it in two separate posts, one on how to read the file in with the extra row, and what i have to change, and one with how to repeat the program 1000 times?

I'm just getting a little confused what instructions go with what task.

Also, if you use the computers clock for random, as im repeating it 1000 times, as it is all done instantly, surely all the random numbers created would be identical?

Andy this is obviously going to give you an error. It doesn't even look like a for loop.

for inFile >> matrix[i][0];

You used for loops in this program. You know what they look like. They look nothing like that.

You say to read the first line of the input file into some variable. How exactly is this done?

You've been reading from the file into integers the whole time with the ">>" operator. matrix[0] is an integer. Replace it with some other integer variable. Look at the big while loop. Changing it to a for loop is not difficult. The brackets all stay in the same place. Just change that one line.

You know how to do a for loop. You know how to read from a file into a variable. You may get confused about where to put stuff, which is fine, but you know that this won't work:

for inFile >> matrix[i][0];

Sorry to be a pain, but could you put it in two separate posts, one on how to read the file in with the extra row, and what i have to change, and one with how to repeat the program 1000 times?

I'm just getting a little confused what instructions go with what task.

Also, if you use the computers clock for random, as im repeating it 1000 times, as it is all done instantly, surely all the random numbers created would be identical?

I haven't commented yet on the repeating it 1000 times. The prior comments deal with changing the program to your new input, not the repeating it 1000 times.

Yes, if you actually run the entire program 1000 times it will seed the random number generator that many times. Since the time function returns the number of seconds since 1970 and the program will take less than a second to run, if you ran the whole program 1000 times, you would indeed be seeding the RNG with the same number many times, and yes, that would defeat the purpose since it would cause the same random numbers to be generated.

Solution? Don't run the program 1000 times. AFTER, and only after you get the program so it can run correctly without any patterns, THEN try making it so it goes through the process 1000 times. Still seed the RNG once, not 1000 times. But you're not running the entire program 1000 times. Just most of it. Create an outer for loop that you go through 1000 times. Have your call to SetSeed be before that outer loop of 1000. Figure out what you want to repeat 1000 times. Something like this:

/* Code that is not to be repeated 1000 times */

SetSeed ();

// Outer for loop start.  Go through 1000 times

     /* code to be repeated 1000 times */

     // Read in number of rows in input file.
     
     /* Start of Inner for loop.  Used to be while loop.
         Go through once for each row of data */

     /* End of inner for loop.   */

     // code to count number of 0's and 1's.  Repeated 1000 times.

// End of outer for loop
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.