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
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
What have you tried so far?
i dont have anything in the main(),i am so stumped i jus need a kick in the right direction
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 ); }
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
>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:
>and how long did it take u to understand thisCode:void f(int& col, int& row);
It doesn't matter. Everyone learns differently.
My best code is written with the delete key.
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;
Code:#include <iostream> void foo ( int &a ) { a = 2 } int main ( ) { int bar = 1; std::cout << bar; foo( bar ); std::cout << bar << std::endl; }
doesnt it have to be random and its output is suppose to be in rows and columns and run 25 times
>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.
My best code is written with the delete key.
Originally Posted by Prelude
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
Last edited by krazykid18; 12-11-2004 at 06:34 PM.
for(int times=0;times<25;times++)Originally Posted by krazykid18
^-------The second term (times<25) is like a boolean. You want it to run as often as that returns true.
To code is divine
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.
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
> for (int times=0;times<25;times++) I'm going to guess that.
To code is divine