minesweeper help

i started to program something like minesweeper, but this doesn't work, can somebody help me please?

#include <iostream>

using namespace std;

int main()
{
int x=10, y=10;
int a, b;
int yn;
int field [x][y];
for (a=0; a<x; a++)
{
for (b=0; b<y; b++)
{
srand(time(NULL));
yn=rand()%2;
field[a][b]=yn;
}
}

cout << field[1][2];

int m, n;

cin >> m;
cin >> n;

if (field[m][n]=1)
{
cout << "bomb";
}

if (field[m][n]=0)
{
cout << "luck";
}


return 0;
}

thx
two things to start with:

first of all, surround your code with code tags and format it so your code looks like this:
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
        int x=10, y=10;
	int a, b;
	int yn;
	int field [x][y];
		for (a=0; a<x; a++)
		{
			for (b=0; b<y; b++)
			{
				srand(time(NULL));
				yn=rand()%2;
				field[a][b]=yn;
			}
		}

	cout << field[1][2];

	int m, n;

	cin >> m;
	cin >> n;

	if (field[m][n]=1)
	{
		cout << "bomb";
	}

	if (field[m][n]=0)
	{
		cout << "luck";
	}


it makes it a lot easier to read. start with (code) and end with (/code) but switch the () with []

ANYWAY.

Try declaring x and y as const. This effectively makes those variables read-only. In short, you need to use const variables when using variables to create arrays.

edit: Also it looks like your
 
srand(time(NULL));

call is a little boned up. I would google how to use that function. It caused an error for me so I just did a c-style cast on the return value of time(NULL) to unsigned int (from time_t) and that fixed the error anyway...
 
srand((unsigned int)time(NULL));
Last edited on
Topic archived. No new replies allowed.