I having trouble with my code this the issue "executeCmd check undo command (0/2), and executeCmd check number of correctly flagged mines (0/2)". This is the code I give you void initField(int num_of_mine) { c00 = c01 = c02 = c03 = c04 = c10 = c11 = c12 = c13 = c14 = c20 = c21 = c22 = c23 = c24 = c30 = c31 = c32 = c33 = c34 = c40 = c41 = c42 = c43 = c44 = c50 = c51 = c52 = c53 = c54 = c60 = c61 = c62 = c63 = c64 = c70 = c71 = c72 = c73 = c74 = UNKNOWN; setMine(num_of_mine); } bool isMine(int i, int j) { int cell = getCell(i, j); return cell == UNFLAGGED_MINE || cell == FLAGGED_MINE; } void reveal(int i,int j) { if (isMine(i, j)) { explode = true; } else { int mineCount = 0; for (int di = -1; di <= 1; di++) { for (int dj = -1; dj <= 1; dj++) { if (di == 0 && dj == 0) continue; int ni = i + di, nj = j + dj; if (ni >= 0 && ni < height && nj >= 0 && nj < width) { if (isMine(ni, nj)) mineCount++; } } } setCell(i, j, mineCount); } } void executeCmd(char action, int row, int col) { switch (action) { case 'f': // Flagging or unflagging a cell if (getCell(row, col) == UNKNOWN) { if (isMine(row, col)) { setCell(row, col, FLAGGED_MINE); num_correct_flagged_mine++; } else { setCell(row, col, INCORRECT_FLAGGED_MINE); num_incorrect_flagged_mine++; } } else if (getCell(row, col) == FLAGGED_MINE) { setCell(row, col, UNKNOWN); num_correct_flagged_mine--; } else if (getCell(row, col) == INCORRECT_FLAGGED_MINE) { setCell(row, col, UNKNOWN); num_incorrect_flagged_mine--; } break; case 'r': reveal(row, col); break; case 'u': if (getCell(row, col) == FLAGGED_MINE) { setCell(row, col, UNKNOWN); num_correct_flagged_mine--; } else if (getCell(row, col) == INCORRECT_FLAGGED_MINE) { setCell(row, col, UNKNOWN); num_incorrect_flagged_mine--; } break; } } can you help what the problem part of my code
I having trouble with my code this the issue "executeCmd check undo command (0/2), and executeCmd check number of correctly flagged mines (0/2)". This is the code I give you
void initField(int num_of_mine) {
c00 = c01 = c02 = c03 = c04 =
c10 = c11 = c12 = c13 = c14 =
c20 = c21 = c22 = c23 = c24 =
c30 = c31 = c32 = c33 = c34 =
c40 = c41 = c42 = c43 = c44 =
c50 = c51 = c52 = c53 = c54 =
c60 = c61 = c62 = c63 = c64 =
c70 = c71 = c72 = c73 = c74 = UNKNOWN;
setMine(num_of_mine);
}
bool isMine(int i, int j) {
int cell = getCell(i, j);
return cell == UNFLAGGED_MINE || cell == FLAGGED_MINE;
}
void reveal(int i,int j) {
if (isMine(i, j)) {
explode = true;
} else {
int mineCount = 0;
for (int di = -1; di <= 1; di++) {
for (int dj = -1; dj <= 1; dj++) {
if (di == 0 && dj == 0) continue;
int ni = i + di, nj = j + dj;
if (ni >= 0 && ni < height && nj >= 0 && nj < width) {
if (isMine(ni, nj)) mineCount++;
}
}
}
setCell(i, j, mineCount);
}
}
void executeCmd(char action, int row, int col) {
switch (action) {
case 'f': // Flagging or unflagging a cell
if (getCell(row, col) == UNKNOWN) {
if (isMine(row, col)) {
setCell(row, col, FLAGGED_MINE);
num_correct_flagged_mine++;
} else {
setCell(row, col, INCORRECT_FLAGGED_MINE);
num_incorrect_flagged_mine++;
}
} else if (getCell(row, col) == FLAGGED_MINE) {
setCell(row, col, UNKNOWN);
num_correct_flagged_mine--;
} else if (getCell(row, col) == INCORRECT_FLAGGED_MINE) {
setCell(row, col, UNKNOWN);
num_incorrect_flagged_mine--;
}
break;
case 'r':
reveal(row, col);
break;
case 'u':
if (getCell(row, col) == FLAGGED_MINE) {
setCell(row, col, UNKNOWN);
num_correct_flagged_mine--;
} else if (getCell(row, col) == INCORRECT_FLAGGED_MINE) {
setCell(row, col, UNKNOWN);
num_incorrect_flagged_mine--;
}
break;
}
} can you help what the problem part of my code
Step by step
Solved in 3 steps with 1 images