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;
}
}
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...