| | |
Getting happy face value instead of O for tic tac toe prog.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 22
Reputation:
Solved Threads: 0
Yes, I have the do while set to go on forever until I get on to the solving part, but while trying to shrink my program down so I can make it more modular, the O's that player 2 have are showing up as a face?
I know I have a logic error with the player 1 and 2 alternating, I'll get that fixed, but first I want to know why my O's are showning up as faces?
I know I have a logic error with the player 1 and 2 alternating, I'll get that fixed, but first I want to know why my O's are showning up as faces?
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> using namespace std; const gRow = 3; const gCol = 3; void showGrid(char grid[][gCol], int); int changeValue(int, int); int main() { char grid[gRow][gCol] = {{'*', '*', '*'}, {'*', '*', '*'}, {'*', '*', '*'}}; int rows, cols; int el = 1; int turn = 1; int num = 1; char player; cout << " TIC TAC TOE" << endl; cout << "Player One: X Player Two: O\n" << endl; do { showGrid(grid, gRow); if (turn % 2) {player = 'X';} else {player = 'O' && num++;} cout << "Player " << num << ", Enter the row and column:"; cin >> rows >> cols; if (grid[rows-1][cols-1] != '*') {cout << "This space is taken... Enter the row and column:\n"; cin >> rows >> cols; } grid[rows - 1][cols - 1] = player; turn++; } while(el = 1); return 0; } void showGrid(char array[][gCol], int numRows) { for (int row = 0; row < numRows; row++) { for (int col = 0; col < gCol; col++) { cout << setw(2) << array[row][col] << " "; } cout << endl; } }
•
•
Join Date: Aug 2008
Posts: 77
Reputation:
Solved Threads: 16
Hmm not exactly sure what that would be happening, but there are still a couple things you need to change. At the top you should declare gRow and gCol as const int - I'm not sure how this even compiles with no type given. Also you should make a loop for getting input rather than an if statement in case the player tries to place a piece in an invalid spot more than once. Another thing to consider is making sure the player enters a valid row and column (between 1 and 3).
•
•
Join Date: Nov 2008
Posts: 392
Reputation:
Solved Threads: 72
Sorry but your errors include :
And that is equivilent to
That means that player == 1 or 0, and both of those are interesting ascii characters to print
hope that helps.
Overall, laying out the code cleanly will greatly reduce errors like this.
else {player = 'O' && num++;} And that is equivilent to
c++ Syntax (Toggle Plain Text)
player = ('O' && num); num++;
That means that player == 1 or 0, and both of those are interesting ascii characters to print

hope that helps.
Overall, laying out the code cleanly will greatly reduce errors like this.
Last edited by StuXYZ; Dec 8th, 2008 at 5:19 pm.
experience is the most expensive way to learn anything
![]() |
Other Threads in the C++ Forum
- Previous Thread: Parsing a char
- Next Thread: USB Dismount not turning off my USB Drive?
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph homeworkhelp homeworkhelper iamthwee ifstream input int integer lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





