I cant get a function to print a matrix

I'm trying to make a function that a can call to print this matrix but when I run the program it gives me the error:
error C2664: 'PrintBoard' : cannot convert parameter 1 from 'int [8][8]' to 'int [][7]'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast.

Any help would be appreciated.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <cstdlib>			// include things
#include <ctime>
using namespace std;

void PrintBoard(int b[7][7])          // define the function to print the board
{
	cout << "________" << endl;
	for(int i=0;i<8;i++)  // loop 8 times for 8 lines
	{
		for(int o=0;o<8;o++)  // loop for the 8 elements on the line
		{
				cout << b[i][o];  // display the current element out of the array
		}
	cout << endl;            // go to a new line to display the next line of matrix
	}
}



int main()											// MINESWEEPER text based - input a co-ord in order to click a square just like normal minus the mouse
{											        // eg         "input a co ordinate"
													//                      3 4      == [3][4]
													//            -----------
													//            |   1X1   |          <--- somewhat like that where X = bomb 
													//            |   111   |



	int b[8][8];    //declare matrix for board
	srand ( (unsigned int)time(NULL) );		
	int bombs = 0;                     // control no of bombs
	int temp = 1;						// temp number for making board
	while ( bombs != 10 )           // sets up the minimum number of mobs on the board at once
	{
		int cx = 0;						// x and y co-ords for the bombs location (b array)
		int cy = 0;
		bombs = 0;						// setting bombs to zero

		for(int ctl = 0; ctl < 8; ctl += 1)           //defining the minesweeper board [8*8]
		{
			cx = 0;
			for(int cnt = 0; cnt < 8; cnt += 1)
			{
				temp = rand() % 6;              // temp = random number between 0 and 5
				if ( temp < 1 )                // if temp == 0
				{b[cx][cy] = 1;}			// then theres a bomb on [cx]cy]
				if ( temp > 0 )
				{b[cx][cy] = 0;}			//if temp != 0 then no bomb on [cx][cy]		
				if (b[cx][cy] == 1)						// if theres a bomb on [cx][cy]
				{bombs += 1;}						// add one onto the counter
				cx += 1;							// repeat for the rest of the line
			}
			cy += 1;								// repeat for the next line and so on

		}										//	breaks out of loop if theres enough bombs
	}
	cout<< "Creating Minefield... Created" << endl;


	PrintBoard(b);            // print the board

}
Last edited on
The error occurs because in your main function you have declared the array as :

int b[8][8]; //declare matrix for board

Then you have the function :

void PrintBoard(int b[7][7])

while it should be

void PrintBoard(int b[8][8])
Topic archived. No new replies allowed.