Tic Tac Toe Problem

This is my program so far. It is meant to use a two-dimensional array to allow two people to play a game of tic tac toe. I use Visual Studio, and although it says it cannot detect any errors, it still will not run the program so far to print out what the game board will look like. It is supposed to print the unused spaces with "*" where the X's and O's will go.

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
  // Dodd_TicTacToeGame.cpp : This program allows two players to play a game of Tic Tac Toe through the use of a two-dimensional array.

#include <iostream>
using namespace std;

//************************
//Prototypes:
//************************
//char playerMove(char board[3][3]);
char displayBoard(char board[3][3]);
//void determineWinner();

int main()
{
	char gameboard[3][3] = { {'*', '*', '*'}, {'*', '*', '*'}, {'*', '*', '*'} };
	
	displayBoard(gameboard);

	/*for (int turn = 0; turn < 9; turn++) {
		gameboard[3][3] = playerMove(gameboard);
		displayBoard(gameboard);
	}
	*/
	return 0;
}
/*
char playerMove(char board[3][3])
{
	int playerNumber, row, column;

	cout << "Player One or Player Two?";
	cin >> playerNumber;
	cout << "Enter a row number: ";
	cin >> row;
	cout << "Enter a column number: ";
	cin >> column;
	
	return board[3][3];
}
*/
char displayBoard(char board[3][3])
{
	cout << "\nCurrently the board looks like this: " << endl;
	cout << "-----------------------" << endl;
	for (int i = 0; i < 3; i++) {
		cout << "| ";
		for (int j = 0; j < 3; j++) {
			cout << board[i][j] << " | ";
		}
	}
	cout << "-------------------" << endl;
}
Dutch is right: if the program just runs and exits then you just aren't seeing the output.

Also, you're printing the contents of the board entirely on one line. In addition, the horizontal lines at top and bottom don't match up with it. Here's a version that looks a little better:
1
2
3
4
5
6
7
8
9
10
11
12
char displayBoard(char board[3][3])
{
        cout << "\nCurrently the board looks like this: " << endl;
        cout << "-------------";
        for (int i = 0; i < 3; i++) {
                cout << "\n| ";
                for (int j = 0; j < 3; j++) {
                        cout << board[i][j] << " | ";
                }
        }
        cout << "\n-------------" << endl;
}

Topic archived. No new replies allowed.