# Thread: arrays of random integers & time

1. Look at how many times you have { with out a mathcing }

2. this runs 50 numbers how can i make it run 25 thru r0w and 25 thru col,this is killing me

srand( (unsigned)time( NULL) );
for(int times=0;times==25;times++)
int a = 0;
int b = 0;
int array;
for (int a = 0; a<25; a++)
cout<<1 + rand() % 10 <<endl;
{for(int b=0; b<25; b++)
cout <<1 + rand() % 10 <<endl;}
funcrand( a,b );
return 0;

3. Can you
b) post the whole program, including whatever funcrand() function does.

4. Originally Posted by Salem
Can you
b) post the whole program, including whatever funcrand() function does.
Code:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <time.h>
using namespace std;
const int numberofrows=25;
const int numberofcolumns=25;
int grid[25][25];
void funcrand(int& row,int& col)
{row=2;
col=3;}
void srand(unsigned int seed);

int main ( )
{
srand( (unsigned)time( NULL) );
for(int times=0;times==25;times++)
int a = 0;
int b = 0;
int array;
for (int a = 0; a<25; a++)
cout<<1 + rand() % 10 <<endl;
{for(int b=0; b<25; b++)
cout <<1 + rand() % 10 <<endl;}
funcrand( a,b );
return 0;
}

5. Your use of braces { and } is poor.

For example, you wrote
Code:
for(int times=0;times==25;times++)
int a = 0;
int b = 0;
Which to the compiler means this
Code:
for(int times=0;times==25;times++) {
int a = 0;
}
int b = 0;
So the first step is to go through your code and put matching { and } around all the statements which you want to be executed as part of each for loop.

Then you can work on the logic problems, of say why for(int times=0;times==25;times++) doesn't execute at all, whereas for(int times=0;times<25;times++) executes 25 times

6. i dont understand u,where should i put the braces,maan i jus started c++

7. Code:
srand( (unsigned)time( NULL) );
int a = 0;
int b = 0;
int array;
for(int times=0;times<25;times++)
for(int a=0; a<25; a++)
{
for(int b=1; b<25; b++)
{
if(times == 10)
{
cout <<1 + rand() % 10 <<endl;
}
}
}
funcrand( a,b );
return 0;

8. int myArray[5][10]; declares a static array of ints. It can conceptualized as a table with 5 rows on 10 ints per row. If you were to put a label on each row they would go from 0-4, and the columns would be labeled from 0-9. myArray[0][0] = 1; will assign the value one to the first int in the first row, whereas myArray[2][6] = 21; will assign the value of 21 to the 7th int in the third row. And myArray[x][y] will access the (y + 1) element of the (x + 1) row. Frequently, nested loops with the outer loop controlling the rows and the inner loop controlling the columns are used when dealing with this type of construct, but you can also deal with this as a single dimensional array if you wish. The math is a bit more convoluted to use unidimensional indexing, but it's actually closer to what the computer actually is doing.