Hello cplusplus users!
My name is Chris and I have a slight problem. I have missed two classes of engineering and my project is due soon, for the last 6 hours I have been beating my head into the ground trying to figure out why my random number array is giving me the same random number for every value in the array! Can anyone please tell me how I can get different random numbers in the array? I have figured out how to make a 2d array on my own and I need to make it have different random numbers! This is what I have, please help!
#include <iostream>
#include <ctime>
using namespace std;
int i, j;
int matrix[8][8]; //Creates an 8*8 Matrix or a 2-dimensional array
void fillmatrix ()
{
srand((unsigned)time(NULL)); //Links the random number generator to the clock
matrix[i][j]=(rand() % 100) + 1; //Produces a random number between 1-100
cout << matrix[i][j]<<" ";
}
int main ()
{
for (i=0; i<8; i++) //This loops the rows
{
for (j=0; j<8; j++) //This loops the columns
fillmatrix ();
cout <<endl;
}
system ("pause");
return 0;
}
I'm sorry vlad, I did not understand what you meant, whether to put the srand after the fillmatrix or before.
Dineyo, thank you a lot for your assistance, it hit me now that all my problems came from forgetting to put the brackets around the for loops. I know one of the rules was to not talk in caps but I feel I must say THANKS A LOT!!! :D