Thread: comparing array contents

  1. #16
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Your intro() function keeps making me me itch

    Alternative:
    Code:
    void intro()
    {
      char str[] = "Tic-Tac-Toe";
      int i;
        
      for(i = 0;str[i];++i)
      {
        cout << str[i];
        Sleep(500);
      }
    
      cout << endl << endl;
    }
    If you understand what you're doing, you're not learning anything.

  2. #17
    C++No0b!!!
    Join Date
    Jul 2005
    Location
    penn
    Posts
    66
    that makes no difference in the main loop of the program. that works fine. can you please help me with whats not working properly?

  3. #18
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Well, at the end of every loop you do z=1;

    How could it ever be player 2's turn if you keep making it player 1's turn?

    Using a decent indentation scheme and keeping your code blocks to a reasonable size (see below) would probably help you locate those kinds of issues a little easier.
    Last edited by itsme86; 08-02-2006 at 01:54 PM.
    If you understand what you're doing, you're not learning anything.

  4. #19
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Also, you should really consider using a function for determining the winner. That's a lot of unnecessarily duplicated code. Just create a function and pass it the character to check for.
    If you understand what you're doing, you're not learning anything.

  5. #20
    C++No0b!!!
    Join Date
    Jul 2005
    Location
    penn
    Posts
    66
    i cant remember because i havent programmed in quite a while, but can you do this:

    Code:
    if( (arr[0][0]=='X' && arr[0][1]=='X' && arr[0][2]=='X') || (arr[1][0]=='X' && arr[1][1]=='X' && arr[1][2]=='X') || (arr[2][0]=='X' && arr[2][1]=='X' && arr[2][2]=='X') || (arr[0][0]=='X' && arr[1][1]=='X' && arr[2][2]=='X') || (arr[0][2]=='X' && arr[1][1]=='X' && arr[2][0]=='X') )
          {
                           cout << endl << p1 << " wins!!!";
                           z=-1;
                           break;
          }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Replies: 4
    Last Post: 03-18-2009, 05:01 PM
  3. Using the debugger to see array contents
    By JohnnyCat in forum C++ Programming
    Replies: 2
    Last Post: 06-23-2005, 02:17 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM