Advertisement
triclops200

Untitled

Nov 30th, 2011
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int Board[9] = {0,0,0,0,0,0,0,0,0};
  5. int P1, P2;
  6.  
  7. bool Taken (int Board[],int x) {
  8.     if(Board[x]!=0)
  9.         return true;
  10.     else
  11.         return false;
  12. }
  13.  
  14. bool Done(int * Board) {
  15.     for(int i = 0; i < 9; i++)
  16.         if(Board[i]!=0)
  17.             return false;
  18.     return true;
  19.  
  20. }
  21.  
  22. int main() {
  23.     while (!Done(Board)){
  24.         cout << "Player 1's turn." << endl;
  25.         cin >> P1;
  26.         if(Taken(Board, P1)) {
  27.                 cout << "That is taken, please select another" << endl;
  28.                 cin >> P1;
  29.         }
  30.         else {
  31.             Board[P1] = 1;
  32.             cout << "You have selected spot " << P1 << endl;
  33.         }
  34.         cout << "Player 2's turn." << endl;
  35.         cin >> P2;
  36.         if(Taken(Board, P2)) {
  37.                 cout << "That is taken, please select another" << endl;
  38.                 cin >> P2;
  39.         }
  40.         else {
  41.             Board[P2] = -1;
  42.             cout << "You have selected spot " << P2 << endl;
  43.         }
  44.     }
  45.     return 0;
  46. }
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement