This code is supposed to accept the input from the user and which ever spot the player chooses it makes it equal to one(for x), but for some reason its not working the way I would like... any help appreciated.. Thanks!
Code:#include <iostream> typedef struct{ int tttPositions[9]; }gameBoard; //function prototypes void displayBoard(gameBoard); void getPlayerChoice(gameBoard); int main(){ gameBoard board; board.tttPositions[0] = 0; board.tttPositions[1] = 0; board.tttPositions[2] = 0; board.tttPositions[3] = 0; board.tttPositions[4] = 0; board.tttPositions[5] = 0; board.tttPositions[6] = 0; board.tttPositions[7] = 0; board.tttPositions[8] = 0; bool playing = true; while (playing == true){ displayBoard(board); getPlayerChoice(board); } } void displayBoard(gameBoard board){ for(int loopNumber = 0; loopNumber <= 8; loopNumber++){ switch(board.tttPositions[loopNumber]){ case 0: std::cout<< " - "; break; case 1: std::cout<< " X "; break; case 2: std::cout<< " O "; break; } if (loopNumber == 2 || loopNumber == 5 || loopNumber == 8){ std::cout<< std::endl; } } } void getPlayerChoice(gameBoard board){ int temp; std::cout<< "Where would you like to place your piece?" << std::endl; std::cin>> temp; std::cin.ignore(); temp -= 1; board.tttPositions[temp] = 1; }