   Please, Help with Functions
  Hello,Im in the process of creating Tic Tac Toe, as my first game, and I've across a problem that is kind of strange to me. Im using member functions, but it says i did not declare them. Please help me [sad]NOTE: Says 'begin', 'end', and 'size' were not declared, but im pretty sure you dont have to declare member functions. Also, i have the #include <algorithm>. In addition, 'iter' is a const iterator (vecotr<int>::const_iterator iter;).heres the piece of code with the errors are coming from:while(!compMove)    {   for(vector<int>::const_iterator iter = comp.begin();iter != comp.end();++iter)   {random_shuffle(comp.begin(), comp.end());if(board[comp] == "X" || board[comp] == "O"){  random_shuffle(comp.begin(), comp.end());win = false;}if(board[comp] != "X" || board[comp] != "O"){board[comp] = "O";break;compMove = true;}   }    }[Edited by - NUCLEAR RABBIT on May 28, 2006 10:49:29 AM]
Quote:In addition, 'iter' is a const iterator (vecotr<int>::const_iterator iter;)Quote:for(int iter = comp.size();;)It seems like your declaring iter to be an int not a const_iterator, which is probably your problem.  And if you are using iterators i think that line should be changed to:for(vector<int>::const_iterator iter = comp.begin();iter != comp.end();++iter)Quote:random_shuffle(iter.begin(), iter.end());What is this doing, shuffling a iterator that points to a single element?  Do you mean comp.begin() and comp.end()?   ;  vbuser, I've made those changes, but the same errors occur.Heres a list of errors is comes up with:- `begin' has not been declared - request for member of non-aggregate type before '(' token - `end' has not been declared and it says the same errors, over and over.;  How are you declaring comp, and how are you declaring board?  And what is the comp variable for?;  vbus, heres my whole function. It includes everything that takes place in the game, except the menu and exit screen.void playGame(){int pMove;int comp;bool win = false;bool compMove = false;vector<string> board;board.push_back("1");board.push_back("2");board.push_back("3");board.push_back("4");board.push_back("5");board.push_back("6");board.push_back("7");board.push_back("8");board.push_back("9");while(!win){ srand(time(0)); comp = rand() % 9 - 1;system("CLS");cout << board[0] << " | " << board[1] << " | " << board[2] << endl << "============\n" << board[3] << " | " << board[4] << " | " << board[5] << endl << "============\n" << board[6] << " | " << board[7] << " | " << board[8] << endl << endl;cin >> pMove;    for(int j = 0; j < 10; ++j)    {   if(pMove == j) board[j-1] = "X";    }   while(!compMove)    {random_shuffle(comp.begin(), comp.end());if(board[comp] == "X" || board[comp] == "O"){  random_shuffle(comp.begin(), comp.end());win = false;}if(board[comp] != "X" || board[comp] != "O"){board[comp] = "O";break;compMove = true;}   }    }if(board[0] == "X" && board[1] == "X" && board[2] == "X") {cout << "\n\nYOU WIN!\n\n";system("PAUSE");   win = true; quitGame();}}The ending where it checks if the user wins is not complete, its just to test if the game works.   ;  Take a look here:void playGame(){int pMove;int comp;Notice how you're creating comp as an int? Try making it a vector<int> instead.Edit: Doing that will cause some problems with other parts of your code. I just noticed that.   ;Quote:for(int j = 0; j < 10; ++j)    {   if(pMove == j) board[j-1] = "X";    }What are you trying to do with this?  Could you not check if pMove is greater than 0 and less than 10?  And since pMove = j then board[j - 1] could become board[pMove - 1].Also what is this doing?Quote:while(!compMove)    {random_shuffle(comp.begin(), comp.end());if(board[comp] == "X" || board[comp] == "O"){  random_shuffle(comp.begin(), comp.end());    win = false;}if(board[comp] != "X" || board[comp] != "O"){    board[comp] = "O";    break;    compMove = true;}   }    };Quote:Original post by vbuser1338Quote:for(int j = 0; j < 10; ++j)    {   if(pMove == j) board[j-1] = "X";    }What are you trying to do with this?  Could you not check if pMove is greater than 0 and less than 10?  And since pMove = j then board[j - 1] could become board[pMove - 1].Also what is this doing?Quote:while(!compMove)    {random_shuffle(comp.begin(), comp.end());if(board[comp] == "X" || board[comp] == "O"){  random_shuffle(comp.begin(), comp.end());    win = false;}if(board[comp] != "X" || board[comp] != "O"){    board[comp] = "O";    break;    compMove = true;}   }    }The first part places an X where the user chooses to move. The second part gets the computers move, and checks where or not there is an X or an O in that sqaure.   ;  I would change:for(int j = 0; j < 10; ++j){if(pMove == j)board[j-1] = "X";}toif(pMove >= 0 && pMove < 10) {board[pMove - 1] = "X"}because it makes more sense.  Also I don't get why you need to shuffle anything to get the computer's move.  If you shuffled the board then the player's moves would get messed up.  Why don't you go:comp = rand() % 9 - 1; inside the loop like you did above and loop until it is a valid move?;  Hey Vbus,Thanks for all your help, man! I finally got it to work [lol]. I remade the tic tac toe game 3 times previous to this final time, trying to get this thing to work. Again, thats for all your help.   