# Thread: arrays of random integers & time

1. i am new i have two questions about functions

1.I need to know how to test my program with a loop of 25 repetitions

2. generate an attack location with rand() function. and pass the variable row and col by refernces

2. What have you tried so far?

3. i dont have anything in the main(),i am so stumped i jus need a kick in the right direction

4. Well a loop would be
for ( int i = 0 ; i < 25 ; i++ )

Picking random numbers is in the FAQ
http://faq.cprogramming.com/cgi-bin/...&id=1043284385

Passing by reference,
Code:
```void foo ( int &a ) {
}
int main ( ) {
int bar;
foo( bar );
}```

5. thank u,but this doesnt help me pass it thru columns and rows

THANk U,and how long did it take u to understand this

6. >but this doesnt help me pass it thru columns and rows
Sure it does. Change a to col and add another parameter exactly like it except named row:
Code:
`void f(int& col, int& row);`
>and how long did it take u to understand this
It doesn't matter. Everyone learns differently.

7. this is what i got i am still confused:

int main ()
{
srand(time(NULL));
int a = rand();
int row,col;
funcrand(row,col);
for (int i= 0 ; i< 25 ; i++ )
row= rand();
return 0;

8. Code:
```#include <iostream>
void foo ( int &a ) {
a = 2
}
int main ( ) {
int bar = 1;
std::cout << bar;
foo( bar );
std::cout << bar << std::endl;
}```

9. doesnt it have to be random and its output is suppose to be in rows and columns and run 25 times

10. >doesnt it have to be random and its output is suppose to be in rows and columns and run 25 times
That's your job. We're helping you, not doing it for you.

11. Originally Posted by Prelude
>doesnt it have to be random and its output is suppose to be in rows and columns and run 25 times
That's your job. We're helping you, not doing it for you.

i have it running numbers,but i cant get it to run 25 times look at what i have wuts wrong:

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

but right now i cant get the other column

12. Originally Posted by krazykid18
i have it running numbers,but i cant get it to run 25 times look at what i have wuts wrong:

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

but right now i cant get the other column
for(int times=0;times<25;times++)
^-------The second term (times<25) is like a boolean. You want it to run as often as that returns true.

13. Unless you only want to loop through one line, you need to put curly braces ( { } 's ) around the code you want to execute 25 times. You'd also have a problem if you had a semicolon after the for statement.

14. this what i got
int main ( )
{
srand( (unsigned)time( NULL) );
for (int times=0;times<25;times++)
int a;
int b;
int grid[25][25];
int random_integer;
for (int a = 0; a<25; a++){
for (int b = 1; b<25; b++){
{random_integer=rand();
cout<<1 + rand() % 10 << a << 1+ rand() % 10 << b <<endl;}
funcrand(a,b);
return 0;
}

but when i run it says unexpected end of file as its error,wut is the problem

15. > for (int times=0;times<25;times++) I'm going to guess that.

Popular pages Recent additions