I am trying to print out an 8 by 8 "chess board". My first step is to set all values in the board to 0. I made a function to do so but it isn't working, and i can't figure out why. I'm trying to, for now, simply print out an 8 by 8 of zero values. This is what I have: (C++)
// set all of board to 0 as a function
// bool function to check for valid moves
// bool function to check if on board
// bool function to check if visited (is 0 if block has not been
visited)
#include <iostream>
using namespace std;
void setToZero(int board[8][8]);
int main()
{
// chess board 8x8
int board[8][8];
// all of the possible moves of the knight
int moves[8][2] = { {2,-1}, {1,-2}, {-1,-2}, {-2,-1},
{-2,1}, {-1,2}, {1,2}, {2,1} };
// function call to set values to 0
setToZero(board);
cout << board;
cin.get();
cin.get();
return 0;
}
void setToZero(int board[8][8])
{
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
board[i][j] =
0;
}
CODE IN C++:
#include <iostream>
using namespace std;
void setToZero(int board[8][8]);
int main()
{
// chess board 8x8
int board[8][8];
// all of the possible moves of the knight
int moves[8][2] = { {2,-1}, {1,-2}, {-1,-2}, {-2,-1}, {-2,1},
{-1,2}, {1,2}, {2,1} };
// function call to set values to 0
setToZero(board);
//displaying the board
int i,j;
for(i=0;i<8;i++){
for(j=0;j<8;j++){
cout<<" "<<board[i][j]<<" ";
}
cout<<""<<endl;
}
return 0;
}
void setToZero(int board[8][8])
{
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
board[i][j] = 0;
}
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.