hey all,
how do one convert an integer that a user has entered into a location is an existing 2-d array?
For example:
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
main(){
int y;
int grid[4][4]={{1,5,9,13},{2,6,10,14},{3,7,11,15},{4,
8,12,16}};
cin>>y;
int u;
int U;
y=grid[u][U];
if (y==grid[3][3]){
cout<<"good";
}
else{
cout<<"bad";
}
}
When I run this, I get a windows error, even tho I get no compiler errors.
The actual array represents basically a game board. The comptuer "moves" 1 up, or 1 down, or 1 diagonally, etc. Obviously, the movement is based on its current position, as denoted by the coordinates (i.e. array[x][y]).
The problem arises when the computer makes an illegal move, such a 2 spaces across. To prevent that, I use an if/then statement, referring to the intended coordinates (array [x][y]), and subtracting from them the coordinated of the present position, which, of course, is itself based on previous movements, etc., etc., starting all the way back with array[0][0]--the computer starts at the top left corner.
The problem is that the coordinates, or [x][y], change, depending on the position on the "board". So I would need to refer to array[x][y] as a variable, as opposed to array[3][3], which is always 16.
I hope that's kinda clear (!)
Thanks
777