Grid game with mines

Hi i have a grid game which i'm making and don't know why the game isn't working as it should. a player should be able to win by flaging all the mines in the grid. The problem i'm having is that i can't win the game i've gone wrong somewhere but can't figure it out. below is the condition i've got.
the full code if that helps. https://pastebin.com/08ngPKGP
Thankyou

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
	else if (Move == 'F')
		{
		  GameBoard[row][col] = 'F';
			if (HiddenBoard[row][col] == 'B')
			{
				NumberOfMinesFound++;
				//what about when more flags than mines
				
			}
			
		}
		else
		{
			cout << "Inncorrect type of Move" << endl;
		}
		DisplayBoard(GameBoard, Dimension);
		cout << "Number of moves made so far is " << NumberOfMoves << endl;
	}
	cout << "Game finished" << endl;
	bool Won;
	if (NumberofMinesToFind-- == NumberOfMinesFound)
	{
		cout << "You have won the Game" << endl;  
wait wait hold on here... you are using some really weird logic here....see this is why its bad to do it like this... like if you explode a mine and you havn't found the number of mines, found turns true and it exits the loop.... but it you ACTUALLY FIND THE NUMBER OF MINES the second condition evaluates to true FOREVER thus it doesn't matter if found is true or false....OMG this is exactly why using or like this is bad. use break instead.

while (Found == false || NumberOfMinesFound == NumberofMinesToFind)


short of a better explanation as to what exactly is happening thats all i got. That and possibly using a char variable for a cin is bad. try using a string instead. That and using endl for whatever reason can cause weird problems try using "\n" instead. Don't ask me why.



Last edited on
while (Found == false || NumberOfMinesFound == NumberofMinesToFind) {
should be
while (Found == false && NumberOfMinesFound != NumberofMinesToFind) {

You continue to play while you're not dead and there are mines remaining.
Topic archived. No new replies allowed.