// Making a chess board with 2d arrays
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int ROWS = 8;
const int COLS = 8;
const string board[ROWS][COLS]= { // initialize the array and create an 8x8 chess board
{'Rk', 'Kt', 'Bi', 'Qu', 'Kg', 'Bi', 'Kt', 'Rk'},
{'Pn', 'Pn', 'Pn', 'Pn', 'Pn', 'Pn', 'Pn', 'Pn'},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{'Pn', 'Pn', 'Pn', 'Pn', 'Pn', 'Pn', 'Pn', 'Pn'},
{'Rk', 'Kt', 'Bi', 'Qu', 'Kg', 'Bi', 'Kt', 'Rk'}
};
cout << "\tHere is a chess board\n\n";
for (int i = 0; i < ROWS; ++i)
{
for (int j = 0; j < COLS; ++j)
cout << board[i][j];
cout << endl;
}
return 0;
}
I'm sure there is a cleaner and simpler way to actually make a chess board, but i'm just starting out.
Compiler error says "invalid conversion from int to char" where i'm defining the chess pieces.

New Topic/Question
Reply




MultiQuote







|