I'm trying to search a 2d array for a row and column entry. The array is arrayShots[BS_GRID_ROWS][BS_GRID_COLS] and the rows would be characters and the columns would be numbers. The constants are declared elsewhere, not within in my code. The rows are A through J and the columns are 1 through 10. Thus arrayShots[0][0] could have [A][1] and so on.
Each pass through my function I will add another combination of row and column to this array. Just before I do this I need to search through the array and make sure the combination I'm entering, is not already inside the array somewhere.
I have two questions:
1) How do I add each entry to the array.
2) How would I search through the array to ensure the entry is not already within the array?
The code below is where I'm at currently:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int
main()
{
int column;
bool duplicate;
char row;
int arrayShots[BS_GRID_ROWS][BS_GRID_COLS];
// srand was already initialized
// randomize row/column entry for the array in combination of A to J and 1 to 10
do {
duplicate = false;
row = (rand() % 10) + 65;
column = (rand() % 10) + 1;
for (char rowCh='A'; rowCh <= 'A'+BS_GRID_ROWS-1; rowCh++)
for (int col=1; col <= BS_GRID_COLS; col++){
if (row,column == arrayShots[rowCh][col]
duplicate = true;
}
} (while duplicate == true);
arrayShots[row][column];
}
| |
So essentially my questions come down to these two lines:
if (row,column == arrayShots[rowCh][col]
and
arrayShots[row][column]
The first line i want to check the array for the random row and column i genereted.
The second line I want to add the row and column I generated to the array.
Am I doing either of these correctly? Really appreciate any help.