I need to check that on a game board (10X10 matrix) the user can't enter in values that are out of the matrix. Right now it only works if the placement of some number of the same character is horizontal. I had to set some specific values to check with my crappy debugger and it returns false (as it should) but when its vertical it gives me a illegal vector index error instead of asking for a new set of coordinates.
this is the specific part with the problem--trimmed down some.
Anything obviously wrong there?
void PlaceChallengerShips (apmatrix <char> &defenBoard)
const int CARRIER = 5, BATTLESHIP = 4, SUBMARINE = 3, CRUISER = 3, DESTROYER = 2;
char alignment, rowLetter;
int column, numRow ;
bool valid = false;
cout<<"From the start of each ship enter the ROW letter,\nthe "
<<"COLUMN number, and a choice of <H>orizontal or <V>ertical Placement\n";
cout<<"Hit ENTER to continue\n";
cout << "SHIP : Aircraft Carrier "<<endl;
rowLetter='A'; column=11; alignment='V';
numRow = int(rowLetter) - 65; //Adjust uppercase Letter to row number
column = column - 1; //Adjust column to Matrix Index
valid = ValidPlacement (defenBoard, numRow, column, CARRIER, alignment );
} while (!valid);
and this is corresponding error producing part of ValidPlacement
bool ValidPlacement ( const apmatrix <char> &grid, int numRow, int column, int ship, char alignment)
bool valid = true;
if (numRow > 9)
valid = false;
cout<<"Illegal move. Enter a row letter from A-J\n";
if (column > 9)
valid = false;
cout<<"Illegal move. Enter a column from 1-10\n";