Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. bool pl1Won();
  4.  
  5. char board[9] = {'o','x','x','o','x','x','o','x','x'};
  6.  
  7. int main()
  8. {
  9. //----------------------------------
  10. char pl1 = 'X';
  11. char pl2 = 'O';
  12. int choice;
  13.  
  14. //----------------------------------------------------------------
  15. cout << "Welcome to the Tic Tac Toe game!\n" << "------------------------" << "\n\n";
  16. cout << "Player 1 has" " " << pl1;
  17. cout << "\nPlayer 2 has" " " << pl2 << endl << endl;
  18. //----------------------------------------------------------------
  19. cout << board[0] << "|" << board[1] << "|" << board[2] << endl;
  20. cout << board[3] << "|" << board[4] << "|" << board[5] << endl;
  21. cout << board[6] << "|" << board[7] << "|" << board[8] << endl << endl;
  22.  
  23. //for()
  24. //{
  25.  
  26. if(pl1Won() == true)
  27. {
  28. cout << "Player 1 has won!";
  29. }
  30.  
  31. //}
  32. //
  33. cin.get();
  34. return 0;
  35. }
  36. bool pl1Won()
  37. {
  38. if (board[2] == 'x' && board[4] == 'x' && board[8] == 'x') // Else if() for the others
  39. {
  40. return true; // Win
  41. }else
  42. {
  43. return false; // Not yet
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement