I am confused...XX.....
But how can i add element into this???
like above??
..... sorry
I am confused...XX.....
But how can i add element into this???
like above??
..... sorry
i think i figure out now hahah
thx thx
I have an example posted already. You have one array -- it has three dimensions. If you're going to initialize it, you have to do it now, when you declare it, and you need to initialize it all (or at least everything you plan to do). So do so. We're going to do the random one later, but we need all 0's so:
Then you need the first array; copy and paste the whole thing in fromCode:{ {{0}},
. And there you are.Code:{{ lots of numbers up to}} }
these should make sense?Code:int matrix[MATRIX_SIZE][MATRIX_SIZE]; int matrix_data[2][MATRIX_SIZE][MATRIX_SIZE]; ={ {{0}}, { {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0}, {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0}, {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0}, {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0}, {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0}, {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0}, {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0}, {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0}, {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0}, {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0}, {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1} };} return matrix_data[0]; int trace_matrix[MATRIX_SIZE][MATRIX_SIZE];
What i need to write in the int main() ?
i think i need to allow the user input and read the data from the array and output.
I am trying to produce the code, but it comes more than 15 errors.
Wt else do u need to modify????
-----------THX---THX-------------
I have put these into the int main() What else is missing? Or i need to define other function??Code:int main() { cout <<"Ender Maze wanted, 0,1,2,3:\n"; cout <<" 0- Random Maze\n"; cout <<" 1- Set Maze (1)\n"; cout <<" 2- Exit\n"; cin >> x; return 0;
plz help
cheers
OIC
This is what i though coz they dun read the input and get the output.
so i need to create a function for the data to process!?
So i need specific 0 is to choose the map [0]
and 1 i choose map[1]??
for(int maze=0; maze<3 ; maze++)
cout<<matrix_size[maze]<<"------"<<matrix_data[n]<<endl;
these should put inside the int main() or void()??
I am really sorry for all these......
You can do it inside main directly, or put it another function, as you wish; but if you put it in another function you do have to call that function from main, or else it won't happen. Notice that there is no function called void().
Sorry
So i think i will put them inside the main...
I have seen the other tread you reply
using printf and scanf
are they more useful for me?? (I know it sounds weired)
I will use that method to see does it get me anywhere.Thanks
I am sorry for all these question, but i really trying to get them work, I have not stopping on these since you repled me this morning ahahaha.
---------Thanks God------------
I have done the following changes in the int main()
still 3 errors, any 1 can point out wt's going on????Code:int main() using namespace std; { int maze; cout <<"Enter Maze wanted, 0,1,2,3:\n"; cout <<" 0- Random Maze\n"; cout <<" 1- Set Maze (1)\n"; cout <<" 2- Exit\n"; cin >> maze; { for (maze =0; maze < matrix_data[n]; maze++) cout<<matrix_data[n] <<endl; }
Thanks Thanks
The three errors tell you exactly what's going on:
unclosed brace on line "{" (right after cin >> maze)
variable n not defined
unable to compare int (maze) with int[][] (matrix_data[n]) (although your error might say something about conversions from int[][] to int)
Not a compile error, probably, but cout << matrix_data[n] will probably print out a hex memory address, since matrix_data[n] decays into a pointer.
Still getting syntax error
Code:int main() using namespace std; { int maze[][], n; cout <<" Enter Maze wanted, 0,1,2:\n"; cout <<" 0- Random Maze\n"; cout <<" 1- Set Maze (1)\n"; cout <<" 2- Exit\n"; cin >> maze[][]; matrix_data[n] =maze[][]; { for (maze[][] =0; maze[][] < matrix_data[n]; maze[][]++) cout<<matrix_data[n] <<endl; printf("%d\n", matrix_data[n]); return 0; } }
i am also having error on this line....
Code:int matrix_data[2][MATRIX_SIZE][MATRIX_SIZE]; ={ {{0}}, { {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0}, {0,
also wt this mean?
"unable to compare int (maze) with int[][] (matrix_data[n]) "
This is the end of it....Code:. . . . ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0}, {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0}, {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1} };} return matrix_data[0]; int trace_matrix[MATRIX_SIZE][MATRIX_SIZE]; void output_program(struct prog *progp) { char *codep = progp->code; int token; while (token = *codep++) fputs(token_table[token].name, stdout); putchar('\n'); } void print_matrix(void) { int i, j; char symbs[] = " OX"; for (i=0; i < MATRIX_SIZE; i++) { for (j=0; j < MATRIX_SIZE; j++) putchar(symbs[trace_matrix[i][j]]); putchar('\n'); } }
So aboe must be wring...Code:for (maze[][] =0; maze[][] << matrix_data[n]; maze[][]++)
If i can't use integer to a matrix,,,, so how can i retrieve the data?
Thanks Thanks
Notice in your initializer that you've embedded the semicolon in the thing, rather than being at the end like it should.
This is so amazingly wrong that it makes me give up hope.Code:for (maze[][] =0; maze[][] << matrix_data[n]; maze[][]++)
matrix_data is a 3-dimensional array.
matrix_data[0] is a 2-dimensional array (namely, a map).
matrix_data[0][1] is a 1-dimensional array (specifically, the second row of the map).
matrix_data[0][1][2] is an integer (the third number in the second row of the map).
You can only deal with specific elements of the array.