# arrays of random integers & time

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 12-11-2004
krazykid18
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
• 12-11-2004
Salem
What have you tried so far?
• 12-11-2004
krazykid18
i dont have anything in the main(),i am so stumped i jus need a kick in the right direction
• 12-11-2004
Salem
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 ); }```
• 12-11-2004
krazykid18
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
• 12-11-2004
Prelude
>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.
• 12-11-2004
krazykid18
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;
• 12-11-2004
Salem
Code:

```#include <iostream> void foo ( int &a ) {     a = 2 } int main ( ) {     int bar = 1;     std::cout << bar;     foo( bar );     std::cout << bar << std::endl; }```
• 12-11-2004
krazykid18
doesnt it have to be random and its output is suppose to be in rows and columns and run 25 times
• 12-11-2004
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.
• 12-11-2004
krazykid18
Quote:

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-11-2004
7smurfs
Quote:

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.
• 12-11-2004
sean
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.
• 12-12-2004
krazykid18
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
• 12-12-2004
7smurfs
> for (int times=0;times<25;times++) I'm going to guess that.
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last