Look at how many times you have { with out a mathcing }
Look at how many times you have { with out a mathcing }
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;
Can you
a) Please use [code][/code]Tags
b) post the whole program, including whatever funcrand() function does.
Originally Posted by SalemCode:#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; }
Your use of braces { and } is poor.
For example, you wrote
Which to the compiler means thisCode: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.Code:for(int times=0;times==25;times++) { int a = 0; } int b = 0;
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
i dont understand u,where should i put the braces,maan i jus started c++
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;
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.