Designing output for a text game requires some thinking — specifically about spaces.
It is most helpful to get out a sheet of graph paper and draw what you want to see, then design the output to work row-by-row, inserting the proper spaces between things.
#include <string>
usingnamespace std;
int main()
{
// SETUP THE BOARD
constint size = 5;
char board[size][size];
for(int r = 0; r < size; ++r)
{
for(int c = 0; c < size; ++c)
board[r][c] = '-';
}
string word = "OFF";
// SETUP FOR HORIZONTAL WORD
int start_row = 2;
int start_col = 1;
// INSERT WORD INTO BOARD
for(int i = 0; i < word.length(); ++i)
board[start_row][start_col + i] = word[i];
// DISPLAY BOARD
for(int r = 0; r < size; ++r)
{
for(int c = 0; c < size; ++c)
cout << board[r][c] << ' ';
cout << '\n';
}
return 0;
}
Obviously r is row, and c is column. Look at this line carefully and vertical words are easy to manage with a fairly minor change board[start_row][start_col + i] = word[i];