I have the program tic-tac toe done and it works but there is one part that is messing up. In the function Game I have it set up so that it keeps playing until count >9. In the function Winners I have it set so that after someone wins it sets count=10, so that it ends the game. However when I run it doesnt recognize the count=10. I know I need to pass the count from the function Winners to the function Game. My question is how do I pass that?
You're passing count by value to the function Winners(). That means Winners only knows about a variable called count, which happens to have the same value as the variable called count in Game().
The problem is getting a value you set in the Winners() function to somewhere that Game() will know about it. There are three primary options.
1) All of your functions currently return void. You could make them return int instead, and assign the return value to the appropriate variable in Game(). This is the "simplest" approach.
2) You could make the relevant variables global, rather than defining them in Game(). This is not recommended, as global variables are usually not good form. However, since you've already got some, one more won't hurt.
3) You could pass the variable count to Winners() "by reference", rather than by value. In this case you really would be dealing with the same variable from Game(), not a copy. This is an advanced concept.
You're passing count by value to the function Winners(). That means Winners only knows about a variable called count, which happens to have the same value as the variable called count in Game().
The problem is getting a value you set in the Winners() function to somewhere that Game() will know about it. There are three primary options.
1) All of your functions currently return void. You could make them return int instead, and assign the return value to the appropriate variable in Game(). This is the "simplest" approach.
2) You could make the relevant variables global, rather than defining them in Game(). This is not recommended, as global variables are usually not good form. However, since you've already got some, one more won't hurt.
3) You could pass the variable count to Winners() "by reference", rather than by value. In this case you really would be dealing with the same variable from Game(), not a copy. This is an advanced concept.
Can you give me an example of the first option? Instead of void Winners() should it be int Winners() and then return count;
Well, logically, you only care about one aspect of the Winners() function in Game()----whether or not someone won. So perhaps it would be more appropriate to declare it as
bool Winners()
instead, and have return true; indicate a win, and return false; indicate otherwise.
Well, logically, you only care about one aspect of the Winners() function in Game()----whether or not someone won. So perhaps it would be more appropriate to declare it as
bool Winners()
instead, and have return true; indicate a win, and return false; indicate otherwise.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.