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.
#include <iostream>
#include <cstdlib> // include things
#include <ctime>
usingnamespace 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 ( (unsignedint)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
}