$ g++ -Wall foo.cpp
foo.cpp: In function ‘void Toggleplayer()’:
foo.cpp:47:14: warning: statement has no effect [-Wunused-value]
player == 'X';
^
foo.cpp: In function ‘int main()’:
foo.cpp:119:16: error: ‘system’ was not declared in this scope
system("pause");
^
@garza07,
You assign the variable player to the matrix array; however, you do not define the player variable on line 4. By the way, why are you using an integer data type on the player variable on line 4? Since you are using the variable to compare characters, did you mean the variable type of the player variable as a char?
On line 47, player == 'X' // Comparing the variable should be player = 'X' \\ Assign the variable.
I would take a look at your win() function when you are determine the winner. On line 52, if (matrix[0][0] == 'X' && matrix[0][1] == 'X' && matrix[0][0] == 'X') do you see the issue on the matrix array comparison?
There are additional minor issues; however, once you begin to debug the code, you may be able to see it.
Could have just opened your on-screen keyboard and detoggled capslock. Anyways I'm probably late as by now you've probably rebooted your system and the capslock would have reset.
don't know why @dutch is being rude. I'm just a kid with keyboard problems lol. and thank you @chicofeo I looked into line 47 and on the matrix and was able to fix it thank you for the help unlike dutch calling me mean names
[...]when starting the game and pressing the first number, nothing comes out its just blank on the number pressed first
@garza, I do not know your updated code. However, the reason the first selection comes out blank is due to the variable player is not initiated.
My suggestion would be to initialize the variable player like char player = 'X'; This would initialize the variable and once the player 1 makes the selection, the letter 'X' will populate (I assume that player 1 will always begin).
I have some suggestions.
1) Improve your indentation. It's hard to read with bad indentation. For instance you didn't indent your second for-loop. And I would have used 3-spaces or a 1 tab-space for indenting.
2) Using a 2D array will only complicate it.
The barrage of if-statements is just horrible.
I would use a one-dimensional array. char board[8] { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
And for input simply do:
1 2 3 4 5 6 7 8 9 10 11
void input()
{
char input; // note that I'm using char instead of int
cout << "press the number you want: ";
cin >> input;
if (board[input-1] == input) // if not already chosen by player
board[input-1] = player_symbol; // set board
else
cout << "Already taken";
}
Anyways you still haven't completed the game. So I'll let you finish your program and then you can ask again for any suggestions. I just wanted to suggest those two things because I think they would help your code. You still have to figure the rest of the logic like how to determine if there's a win and etc. on your own. I think you will especially become confused while trying to check for wins in a 1D array.
There are lots of other things like not using a global variable for the board and etc. but you don't worry about it for now.