Hi, i'm trying to create a minesweeper board in visual studio. So far I've managed to set up two boards using arrays(a visible play board for the user and a hidden board containing the bombs).
I've managed to randomly input the bombs on to the hidden board and now i need to create a loop that checks each cell in the hidden board to see how many mines are in the adjacent cells. After checking each cell the loop then needs to place a number on the hidden board representing the total adjacent mines to that cell.
The problem i'm having atm is after creating the loop not all the bomb counts are as they should be e.g. some cells show a number 4 despite only being next to 1 bomb. If anyone could tell me what I've done wrong or point me in the right direction it would be greatly appreciated.
I think that the problem is that you are comparing to 0 instead of 9.
1 2 3 4 5
if (x > 0 && y > 0) { // top left
if (hide[x - 1][y - 1] == 0) {
num++; ^
} should be 9
}
You should also not call srand(time(0)) inside the a loop like that. That reseeds the random generator each time and since time(0) returns the number of seconds it means you will get the same X and Y values during the whole second. That is why it takes 8 seconds before the program prints anything. What you should do instead is call it once, at the beginning of main().