tictactoe

im trying to write tictactoe using struct.
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
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
struct board {
 int board_height;
 int board_width;
char board_tiles;
char board[][3];
};
struct playerTurn {
char p1_slot_pick;
char p2_slot_pick;
bool player_turn;
};
void drawBoard(board);
void updateBoard();
playerTurn decisionTurn() {
     playerTurn myPlayerTurn;
    srand(time (NULL));
  int random = rand() % 2 + 1;
    if ( random == 1 ) myPlayerTurn.player_turn = true;
    else if ( random == 2 ) myPlayerTurn.player_turn = false;
        return myPlayerTurn;
}
playerTurn playerTurns(playerTurn newPlayerTurn) {
    if ( newPlayerTurn.player_turn == true ) {
        cout << "Player 1's turn!" << endl;
    cin >> newPlayerTurn.p1_slot_pick;
}
else {
 cout << "Player 2's turn!" << endl;
        cin >> newPlayerTurn.p2_slot_pick;
}
return newPlayerTurn;
}
board iBoard () { // iBoard = initialize board
board myBoard;
myBoard.board_height = 3;
myBoard.board_width = 3;
myBoard.board_tiles = '1';
myBoard.board[myBoard.board_height][myBoard.board_width];
for ( int h = 0; h < myBoard.board_height; h++ ) {
    for ( int w = 0; w < myBoard.board_width; w++ ) {
        myBoard.board[h][w] = myBoard.board_tiles;
    myBoard.board_tiles++;
    }
}
return myBoard;
}
int main() {
    board mainBoard = iBoard();
    drawBoard(mainBoard);
 playerTurn mainPlayerTurn = decisionTurn();
 mainPlayerTurn = playerTurns(mainPlayerTurn);
}
void drawBoard(board drawBoard) {
for ( int h = 0; h < drawBoard.board_height; h++ ) {
    for ( int w = 0; w < drawBoard.board_width; w++ )
        cout << drawBoard.board[h][w];
    cout << endl;
}
}

my problem is that the output is
output:
123

//there's something here that is supposed to be 8 and 9
the output should be
output:
123
456
789


but ive already done this tictactoe game in traditional programming
Last edited on
Topic archived. No new replies allowed.