🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #76

problem with array

#76
From: andrewtitus
Date: Sun, 09 Sep 2001 19:38
137 lines
5008 bytes
The program compiles and runs now. I still have a problem with my Starter
value being placed in board[2][3] though. I have stared at it and tried
different things and still nothing. My array board[][] is set to all 0's in
the constructor and my Starter variable is not even connected to array but
it still takes that value. Can someone point me in the right direction.

Thank You,
Andy

#include <iostream>


using namespace std;

// initalize 3x3 array board
TicTacToe::TicTacToe()
{
   for(int i = 1; i <= 3; i++)
     for(int j = 1; j <= 3; j++)
        board[i][j] = 0;
}
// end constructor array initalization

// deconstructor
TicTacToe::~TicTacToe() {}
// end deconstructor

//-------------------------------------------------------------------------
// display game and rule information
void TicTacToe::displayRules() {

    clrscr();
    cout << "*** WELCOME TO TIC-TAC-TOE ***" << endl;
    cout << "Player 1: for each square chosen a 1 will appear" << endl;
    cout << "Player 2: for each square chosen a 2 will appear" << endl;
    cout << "You will enter the square you want by:\n";
    cout << "1) choosing a square with a 0\n";
    cout << "2) by selecting row and column\n";
    cout << endl;

} //end displayRules()
//-------------------------------------------------------------------------
// find out which player will start first
void TicTacToe::whoStarts() {

    cout << "1) Player1" << endl;
    cout << "2) Player2" << endl;
    cout << "\nPlease enter who will start first: ";
    cin >> Starter;


} // end whoStarts()
//-------------------------------------------------------------------------
// play game function
void TicTacToe::playGame() {

     int i=0,j=0;

     // get row and column position of next move from user
     cout << "Where would you like to move first player "<< Starter <<": "
     << endl;
     cout << "ROW: ";
        cin  >> i;
     cout << "COLUMN: ";
        cin >> j;


     // test to see if space is empty
     while( board[i][j] != 0 )
      {

        cout << "Pick space with a 0 for move: " << endl;
        cout << "ROW: ";
        cin  >> i;
        cout << "COLUMN: ";
        cin >> j;
      }

     // set starter to either 1 or 2 to board[i][j]
     board[i][j] = Starter;

     // switch personUp to next player
     if( Starter == PLAYER1 )
         Starter = PLAYER2;
     else
         Starter = PLAYER1;


} // end playGame()



//-------------------------------------------------------------------------
// to be added later
// gameOver -- tell user' if there is a winner
/*void TicTacToe::gameOver() {

     gameStatus game;

} // end gameOver
*/
//------------------------------------------------------------------------


// displayBoard-- displays game board to user'
void TicTacToe::displayBoard() {

/*

  It seems to be messed up in here. For some reason it is takeing my
  value for starter and placing it in board[2][3].

*/
     clrscr();         // clears screen

     cout << "board[2][3]: " << board[2][3];     // this is a test!!!

     // reinitializes array board[][]
     for(int i = 1; i <= 3; i++)  {
        for(int j = 1; j <= 3; j++)
           if(board[i][j] != PLAYER1)
             if(board[i][j] != PLAYER2)
               board[i][j] = 0;
     } // end for loop

     // display board
     for(int i = 1; i <= 3; i++) {
       cout << endl;
         for(int j = 1; j <= 3; j++)
            cout << board[i][j] << " ";
     } // end for loop



     cout << endl << endl;

} // end displayBoard()
Technical Details
Message-ID: <uyPm7.407268$ai2.30466261@bin2.nnrp.aus1.giganews.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!cpk-news-hub1.bbnplanet.com!news.gtei.net!nf3.bellglobal.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!nntp3.aus1.giganews.com!bin2.nnrp.aus1.giganews.com.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 114592,ff7aa7ba35287504,start
X-Google-Attributes: gid114592,public
X-Google-Thread: 10d4ba,ff7aa7ba35287504,start
X-Google-Attributes: gid10d4ba,public
X-Google-ArrivalTime: 2001-09-09 12:38:19 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!cpk-news-hub1.bbnplanet.com!news.gtei.net!nf3.bellglobal.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!nntp3.aus1.giganews.com!bin2.nnrp.aus1.giganews.com.POSTED!not-for-mail
Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++
Subject: problem with array
From: andrewtitus@alltel.net
X-Newsreader: News Rover 6.5.1 (http://www.NewsRover.com)
Lines: 137
Message-ID: <uyPm7.407268$ai2.30466261@bin2.nnrp.aus1.giganews.com>
NNTP-Posting-Date: Sun, 09 Sep 2001 14:38:02 CDT
Organization: Giganews.Com - Premium News Outsourcing
X-Trace: sv3-7rcO/ZhxQsAxB7xP5V2e/fBPmGwUvpLyDhthvmHHVI0mhTo32Jhy/5lzKj0q6lLwpt2i0w/GhMjhemD!Nsf3ZHinIMu48f7G/JbxsUFvO9kSBLUgKiTYirnN6OmJ5KSuBHYbiHTdBADorimH9mIQGrKdbjIq!R98=
X-Complaints-To: abuse@GigaNews.Com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-Info: Please be sure to forward a copy of ALL headers
X-Abuse-Info: Otherwise we will be unable to process your complaint properly
Date: Sun, 09 Sep 2001 19:38:02 GMT