tic tac toe troubles...

This is a discussion on tic tac toe troubles... within the Game Programming forums, part of the General Programming Boards category; Hi, I'm not really sure if this is classified as a compiler problem, or a C++ problem, so I put ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    62

    Unhappy tic tac toe troubles...

    Hi, I'm not really sure if this is classified as a compiler problem, or a C++ problem, so I put it here, in this section; I made a tic tac toe game, I finally got it to compile without error; However, when I start up a two player game and input player 1's choice, it prints the board, and then prints a hell of a lot of gibberish...The .cpp file and the executable are located in a zip file, on a german server, but just click the button that contains the word "downloaden" and a few other miscellaneous words...

    Here's the link:
    http://www.myupload.biz/f/9q9/66746/TicTacToe.zip

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    I prefer seeing code here, and compiling it myself.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    62
    Okay fine, here is the code, there is like 500+ lines...

    Code:
    #include <iostream>	 //cout & cin function
    #include <cstdlib>
    #include <string>
    #include <windows.h> //system functions
    #include <conio.h>
    #include <stdio.h>
    
    using namespace std;
    
    void MENU();		//Decides what option to execute
    void EXIT();		//Gives variable to exit
    void RorQ();		//Decides to restart or quit
    void clrscr();		//Clears the screen
    
    class variable
    {
    	public:
    		int I;
    		int menu;		//Variable for deciding the option
    		char rq[1];		//Variable for 'r' or 'q' (restart or quit)
    		int exit;
    };
    class variable C;	//Assigns class to C
    
    void setcolor(unsigned short color)
    { 
    	HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); 
    	SetConsoleTextAttribute(hCon,color); 
    }
    int main()
    {
    	C.I = 2;
    	setcolor(C.I); // changes the color
    	cout << "++++++++++++++++   ++++++++++++++++  ++++++++++++++++\n";
    	cout << "+              +   +              +  +              +\n";
    	cout << "++++++    ++++++   ++++++    ++++++  +    +++++++++++\n";
    	cout << "     +    +             +    +       +    +          \n";
    	cout << "     +    +             +    +       +    +          \n";
    	cout << "     +    +             +    +       +    +          \n";
    	cout << "     +    +             +    +       +    +          \n";
    	cout << "     +    +             +    +       +    +          \n";
    	cout << "     +    +        ++++++    ++++++  +    +++++++++++\n";
    	cout << "     +    +        +              +  +              +\n";
    	cout << "     ++++++        ++++++++++++++++  ++++++++++++++++\n";
    	cout << "\n\n";
    	cout << "++++++++++++++++   ++++++++++++++++  ++++++++++++++++\n";
    	cout << "+              +   +              +  +              +\n";
    	cout << "++++++    ++++++   +    ++++++    +  +    +++++++++++\n";
    	cout << "     +    +        +    +    +    +  +    +          \n";
    	cout << "     +    +        +    +    +    +  +    +          \n";
    	cout << "     +    +        +    +    +    +  +    +          \n";
    	cout << "     +    +        +    +    +    +  +    +          \n";
    	cout << "     +    +        +    ++++++    +  +    +          \n";
    	cout << "     +    +        +    +    +    +  +    +++++++++++\n";
    	cout << "     +    +        +    +    +    +  +              +\n";
    	cout << "     ++++++        ++++++    ++++++  ++++++++++++++++\n";
    	cout << "\n\n";
    	cout << "++++++++++++++++   ++++++++++++++++  ++++++++++++++++\n";
    	cout << "+              +   +              +  +              +\n";
    	cout << "++++++    ++++++   +    ++++++    +  +    +++++++++++\n";
    	cout << "     +    +        +    +    +    +  +    +          \n";
    	cout << "     +    +        +    +    +    +  +    ++++++++   \n";
    	cout << "     +    +        +    +    +    +  +           +   \n";
    	cout << "     +    +        +    +    +    +  +    ++++++++   \n";
    	cout << "     +    +        +    +    +    +  +    +          \n";
    	cout << "     +    +        +    ++++++    +  +    +++++++++++\n";
    	cout << "     +    +        +              +  +              +\n";
    	cout << "     ++++++        ++++++++++++++++  ++++++++++++++++\n";
    	C.exit = 1;
    	while (C.exit == 1)
    	{
    		int x, y, win, player;
    		string xy[3][3];
    		string playerc;
    		MENU();
    		switch (C.menu) //A switch statement that chooses the math option
    		{
    			xy[1][1]=" ";
    			xy[1][2]=" ";
    			xy[1][3]=" ";
    			xy[2][1]=" ";
    			xy[2][2]=" ";
    			xy[2][3]=" ";
    			xy[3][1]=" ";
    			xy[3][2]=" ";
    			xy[3][3]=" ";
    			case 0:
    				EXIT();
    				cin.get();
    				C.exit = 0;
    				break;
    			case 1:
    				cout << "What part of \"Not Yet Functional\" do you not understand?\n";
    				system("pause");
    				main();
    				break;
    			case 2:
    				clrscr();
    				cout << "\t\tInstructions\n";
    				cout << "Player 1 is X's, while Player 2 is O's\n";
    				cout << "Player 1 goes first. The object of this game is to get three of your sign\n";
    				cout << "in a row, whether it be vertically, horizontally, or diagonally.\n\n";
    				
    				system("pause");
    
    				cout << "\t\tTIC-TAC-TOE\n";
    				cout << "\t______Two Player Game______\n\n";
    				cout << "\t\t       1     2     3\n\n";
    				cout << "\t\t          |     |     \n";
    				cout << "\t\tA(1)      |     |     \n";
    				cout << "\t\t     _____|_____|_____\n";
    				cout << "\t\t          |     |     \n";
    				cout << "\t\tB(2)      |     |     \n";
    				cout << "\t\t     _____|_____|_____\n";
    				cout << "\t\t          |     |     \n";
    				cout << "\t\tC(3)      |     |     \n";
    				cout << "\t\t          |     |     \n\n";
    				win = 1;
    				player = 1;
    				while (win==1)
    				{
    					while (player==1)
    					{
    						playerc = "x";
    						cout << "Player 1, enter the number of the row you wish to move to: ";
    						cin >> x;
    						cout << "Now enter the number of the column you wish to move to: ";
    						cin >> y;
    						xy[x][y]=playerc;
    						system("pause");
    						cout << "\t\t       1     2     3\n\n";
    						cout << "\t\t          |     |     \n";
    						cout << "\t\tA(1)   "<<xy[1][1]<<"  |  "<<xy[1][2]<<"  |  "<<xy[1][3]<<"  \n";
    						cout << "\t\t     _____|_____|_____\n";
    						cout << "\t\t          |     |     \n";
    						cout << "\t\tB(2)   "<<xy[2][1]<<"  |  "<<xy[2][2]<<"  |  "<<xy[2][3]<<"  \n";
    						cout << "\t\t     _____|_____|_____\n";
    						cout << "\t\t          |     |     \n";
    						cout << "\t\tC(3)   "<<xy[3][1]<<"  |  "<<xy[3][2]<<"  |  "<<xy[3][3]<<"  \n";
    						cout << "\t\t          |     |     \n\n";
    						cin.get();
    						if (xy[1][1]==playerc)
    						{
    							if (xy[1][2]==playerc)
    							{
    								if (xy[1][3]==playerc)
    								{
    									if (playerc=="x")
    									{
    										win = 2;
    									}
    									else if (playerc=="o")
    									{
    										win = 3;
    									}
    									else
    									{
    										win = 1;
    									}
    								}
    								else
    								{
    									win = 1;
    								}
    							}
    							else if (xy[2][1]==playerc)
    							{
    								if (xy[3][1]==playerc)
    								{
    									if (playerc=="x")
    									{
    										win = 2;
    									}
    									else if (playerc=="o")
    									{
    										win = 3;
    									}
    									else
    									{
    										win = 1;
    									}
    								}
    								else
    								{
    									win = 1;
    								}
    							}
    							else if (xy[2][2]==playerc)
    							{
    								if (xy[3][3]==playerc)
    								{
    									if (playerc=="x")
    									{
    										win = 2;
    									}
    									else if (playerc=="o")
    									{
    										win = 3;
    									}
    									else
    									{
    										win = 1;
    									}
    								}
    								else
    								{
    									win = 1;
    								}
    							}
    							else
    							{
    								win = 1;
    							}
    						}
    						else if (xy[2][1]==playerc)
    						{
    							if (xy[2][2]==playerc)
    							{
    								if (xy[2][3]==playerc)
    								{
    									if (playerc=="x")
    									{
    										win = 2;
    									}
    									else if (playerc=="o")
    									{
    										win = 3;
    									}
    									else
    									{
    										win = 1;
    									}	
    								}
    								else
    								{
    									win = 1;
    								}
    							}
    							else
    							{
    								win = 1;
    							}
    						}
    						else if (xy[3][1]==playerc)
    						{
    							if (xy[3][2]==playerc)
    							{
    								if (xy[3][3]==playerc)
    								{
    									if (playerc=="x")
    									{
    										win = 2;
    									}
    									else if (playerc=="o")
    									{
    										win = 3;
    									}
    									else
    									{
    										win = 1;
    									}
    								}
    								else
    								{
    									win = 1;
    								}
    							}
    							else if (xy[2][2]==playerc)
    							{
    								if (xy[1][3]==playerc)
    								{
    									if (playerc=="x")
    									{
    										win = 2;
    									}
    									else if (playerc=="o")
    									{
    										win = 3;
    									}
    									else
    									{
    										win = 1;
    									}
    								}
    								else
    								{
    									win = 1;
    								}
    							}
    						}
    						switch (win)
    						{				
    							case 1:
    								player = 2;
    								break;
    							case 2:
    								cout << "Congrats Player 1, you have won!";
    								RorQ();
    								break;
    							default:
    								player = 2;
    								break;
    						}
    					}
    					while (player==2)
    					{
    						playerc = "o";
    						cout << "Player 2, enter the number of the row you wish to move to: ";
    						cin >> x;
    						cout << "Now enter the number of the column you wish to move to: ";
    						cin >> y;
    						xy[x][y]="o";
    						system("pause");
    						cout << "\t\t       1     2     3\n\n";
    						cout << "\t\t          |     |     \n";
    						cout << "\t\tA(1)   "<<xy[1][1]<<"  |  "<<xy[1][2]<<"  |  "<<xy[1][3]<<"  \n";
    						cout << "\t\t     _____|_____|_____\n";
    						cout << "\t\t          |     |     \n";
    						cout << "\t\tB(2)   "<<xy[2][1]<<"  |  "<<xy[2][2]<<"  |  "<<xy[2][3]<<"  \n";
    						cout << "\t\t     _____|_____|_____\n";
    						cout << "\t\t          |     |     \n";
    						cout << "\t\tC(3)   "<<xy[3][1]<<"  |  "<<xy[3][2]<<"  |  "<<xy[3][3]<<"  \n";
    						cout << "\t\t          |     |     \n\n";
    						if (xy[1][2]==playerc)
    						{
    							if (xy[1][3]==playerc)
    							{
    								if (playerc=="x")
    								{
    									win = 2;
    								}
    								else if (playerc=="o")
    								{
    									win = 3;
    								}
    								else
    								{
    									win = 1;
    								}
    							}
    							else
    							{
    								win = 1;
    							}
    						}
    						else if (xy[2][1]==playerc)
    						{
    							if (xy[3][1]==playerc)
    							{
    								if (playerc=="x")
    								{
    									win = 2;
    								}
    								else if (playerc=="o")
    								{
    									win = 3;
    								}
    								else
    								{
    									win = 1;
    								}
    							}
    							else
    							{
    								win = 1;
    							}
    						}
    						else if (xy[2][2]==playerc)
    						{
    							if (xy[3][3]==playerc)
    							{
    								if (playerc=="x")
    								{
    									win = 2;
    								}
    								else if (playerc=="o")
    								{
    									win = 3;
    								}
    								else
    								{
    									win = 1;
    								}
    							}
    							else
    							{
    								win = 1;
    							}
    						}
    						else
    						{
    							win = 1;
    						}
    						if (xy[2][1]==playerc)
    						{
    							if (xy[2][2]==playerc)
    							{
    								if (xy[2][3]==playerc)
    								{
    									if (playerc=="x")
    									{
    										win = 2;
    									}
    									else if (playerc=="o")
    									{
    										win = 3;
    									}
    									else
    									{
    										win = 1;
    									}	
    								}
    								else
    								{
    									win = 1;
    								}
    							}
    							else
    							{
    								win = 1;
    							}
    						}
    						else if (xy[3][1]==playerc)
    						{
    							if (xy[3][2]==playerc)
    							{
    								if (xy[3][3]==playerc)
    								{
    									if (playerc=="x")
    									{
    										win = 2;
    									}
    									else if (playerc=="o")
    									{
    										win = 3;
    									}
    									else
    									{
    										win = 1;
    									}
    								}
    								else
    								{
    									win = 1;
    								}
    							}
    							else if (xy[2][2]==playerc)
    							{
    								if (xy[1][3]==playerc)
    								{
    									if (playerc=="x")
    									{
    										win = 2;
    									}
    									else if (playerc=="o")
    									{
    										win = 3;
    									}
    									else
    									{
    										win = 1;
    									}
    								}
    								else
    								{
    									win = 1;
    								}
    							}
    						}
    						switch (win)
    						{				
    							case 1:
    								player = 1;
    								break;
    							case 2:
    								cout << "Congrats Player 2, you have won!";
    								RorQ();
    								break;
    							default:
    								player = 1;
    								break;
    						}
    					}
    				break;
    			case 3:
    				cout << "\t\tTic-Tac-Toe\n";
    				cout << "\t\tBy Michael Kylman\n\n";
    				cout << "Well, so far this game has no substance at all, it's just a menu!";
    				
    				system("pause");
    				RorQ();
    				break;
    			default:
    				cout << "Sorry thats an incorrect choice!" <<"\n";
    				RorQ();
    				break;
    			}
    			clrscr();
    	}
    		cin.get();
    		return 0;
    	}
    }
    void MENU() //Gives user the choice of what math option to make
    { 
    	cout << "\n\n";
    	cout << "\t\tMENU\n";
    	cout << "0. EXIT GAME"<<"\n";			               //Exits program
    	cout << "1. 1 Player Game(Not Yet Functional)" <<"\n"; //Adds two numbers
    	cout << "2. 2 Player Game"<<"\n";	                   //Subtracts two numbers
    	cout << "3. ABOUT" <<"\n";			                   //About the program
    	cout << "Enter the number of your selection>";
    	cin  >> C.menu;
    	clrscr();
    }
    
    void EXIT()
    {
    	cout << "Goodbye, Thanks for Playing!\n";
    	C.exit=0;
    }
    
    void RorQ() //Gives user the option to restart or quit
    {
    	clrscr();
    	cout << "Press (r) to Return to the menu or (q) to Quit\n";
    	cout << ">";
    	cin  >> C.rq[1];
    	cin.ignore();
    
    	if(C.rq[1] == 'r')
    	{
    		clrscr();
    		main();
    	}
    	else if(C.rq[1] == 'q')
    	{
    		EXIT();
    	}
    	else
    	{
    		cout << "Thats not a valid choice... Please rechoose" << "\n";
    		RorQ();
    	}
    }
    void clrscr() //Clears the screen
    {
        COORD coordScreen = { 0, 0 };
        DWORD cCharsWritten;
        CONSOLE_SCREEN_BUFFER_INFO csbi;
        DWORD dwConSize;
        HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        
        GetConsoleScreenBufferInfo(hConsole, &csbi);
        dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
        FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
        GetConsoleScreenBufferInfo(hConsole, &csbi);
        FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
        SetConsoleCursorPosition(hConsole, coordScreen);
    }
    Just a note, but I didn't write the clrscr() function, I took it, so I have no idea what it does... :-) anyway, there's the code, for those who don't wanna download it...

  4. #4
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    I painted your code, so it is easier to read now:
    Code:
    #include <iostream>       //cout & cin function
    #include <cstdlib>
    #include <string>
    #include <windows.h> //system functions
    #include <conio.h>
    #include <stdio.h>
    
    using namespace std;
    
    void MENU();            //Decides what option to execute
    void EXIT();            //Gives variable to exit
    void RorQ();            //Decides to restart or quit
    void clrscr();            //Clears the screen
    
    class variable
    {
          public:
                int I;
                int menu;            //Variable for deciding the option
     char rq[1];            //Variable for 'r' or 'q' (restart or quit)
     int exit;
    };
    class variable C;      //Assigns class to C
    
    void setcolor(unsigned short color)
    { 
          HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); 
          SetConsoleTextAttribute(hCon,color); 
    }
    int main()
    {
          C.I = 2;
          setcolor(C.I); // changes the color
     cout << "++++++++++++++++   ++++++++++++++++  ++++++++++++++++\n";
          cout << "+              +   +              +  +              +\n";
          cout << "++++++    ++++++   ++++++    ++++++  +    +++++++++++\n";
          cout << "     +    +             +    +       +    +          \n";
          cout << "     +    +             +    +       +    +          \n";
          cout << "     +    +             +    +       +    +          \n";
          cout << "     +    +             +    +       +    +          \n";
          cout << "     +    +             +    +       +    +          \n";
          cout << "     +    +        ++++++    ++++++  +    +++++++++++\n";
          cout << "     +    +        +              +  +              +\n";
          cout << "     ++++++        ++++++++++++++++  ++++++++++++++++\n";
          cout << "\n\n";
          cout << "++++++++++++++++   ++++++++++++++++  ++++++++++++++++\n";
          cout << "+              +   +              +  +              +\n";
          cout << "++++++    ++++++   +    ++++++    +  +    +++++++++++\n";
          cout << "     +    +        +    +    +    +  +    +          \n";
          cout << "     +    +        +    +    +    +  +    +          \n";
          cout << "     +    +        +    +    +    +  +    +          \n";
          cout << "     +    +        +    +    +    +  +    +          \n";
          cout << "     +    +        +    ++++++    +  +    +          \n";
          cout << "     +    +        +    +    +    +  +    +++++++++++\n";
          cout << "     +    +        +    +    +    +  +              +\n";
          cout << "     ++++++        ++++++    ++++++  ++++++++++++++++\n";
          cout << "\n\n";
          cout << "++++++++++++++++   ++++++++++++++++  ++++++++++++++++\n";
          cout << "+              +   +              +  +              +\n";
          cout << "++++++    ++++++   +    ++++++    +  +    +++++++++++\n";
          cout << "     +    +        +    +    +    +  +    +          \n";
          cout << "     +    +        +    +    +    +  +    ++++++++   \n";
          cout << "     +    +        +    +    +    +  +           +   \n";
          cout << "     +    +        +    +    +    +  +    ++++++++   \n";
          cout << "     +    +        +    +    +    +  +    +          \n";
          cout << "     +    +        +    ++++++    +  +    +++++++++++\n";
          cout << "     +    +        +              +  +              +\n";
          cout << "     ++++++        ++++++++++++++++  ++++++++++++++++\n";
          C.exit = 1;
          while (C.exit == 1)
          {
                int x, y, win, player;
                string xy[3][3];
                string playerc;
                MENU();
                switch (C.menu) //A switch statement that chooses the math option
                {
                      xy[1][1]=" ";
                      xy[1][2]=" ";
                      xy[1][3]=" ";
                      xy[2][1]=" ";
                      xy[2][2]=" ";
                      xy[2][3]=" ";
                      xy[3][1]=" ";
                      xy[3][2]=" ";
                      xy[3][3]=" ";
                      case 0:
                            EXIT();
                            cin.get();
                            C.exit = 0;
                            break;
                      case 1:
                            cout << "What part of \"Not Yet Functional\" do you not understand?\n";
                            system("pause");
                            main();
                            break;
                      case 2:
                            clrscr();
                            cout << "\t\tInstructions\n";
                            cout << "Player 1 is X's, while Player 2 is O's\n";
                            cout << "Player 1 goes first. The object of this game is to get three of your sign\n";
                            cout << "in a row, whether it be vertically, horizontally, or diagonally.\n\n";
                            
                            system("pause");
    
                            cout << "\t\tTIC-TAC-TOE\n";
                            cout << "\t______Two Player Game______\n\n";
                            cout << "\t\t       1     2     3\n\n";
                            cout << "\t\t          |     |     \n";
                            cout << "\t\tA(1)      |     |     \n";
                            cout << "\t\t     _____|_____|_____\n";
                            cout << "\t\t          |     |     \n";
                            cout << "\t\tB(2)      |     |     \n";
                            cout << "\t\t     _____|_____|_____\n";
                            cout << "\t\t          |     |     \n";
                            cout << "\t\tC(3)      |     |     \n";
                            cout << "\t\t          |     |     \n\n";
                            win = 1;
                            player = 1;
                            while (win==1)
                            {
                                  while (player==1)
                                  {
                                        playerc = "x";
                                        cout << "Player 1, enter the number of the row you wish to move to: ";
                                        cin >> x;
                                        cout << "Now enter the number of the column you wish to move to: ";
                                        cin >> y;
                                        xy[x][y]=playerc;
                                        system("pause");
                                        cout << "\t\t       1     2     3\n\n";
                                        cout << "\t\t          |     |     \n";
                                        cout << "\t\tA(1)   "<<xy[1][1]<<"  |  "<<xy[1][2]<<"  |  "<<xy[1][3]<<"  \n";
                                        cout << "\t\t     _____|_____|_____\n";
                                        cout << "\t\t          |     |     \n";
                                        cout << "\t\tB(2)   "<<xy[2][1]<<"  |  "<<xy[2][2]<<"  |  "<<xy[2][3]<<"  \n";
                                        cout << "\t\t     _____|_____|_____\n";
                                        cout << "\t\t          |     |     \n";
                                        cout << "\t\tC(3)   "<<xy[3][1]<<"  |  "<<xy[3][2]<<"  |  "<<xy[3][3]<<"  \n";
                                        cout << "\t\t          |     |     \n\n";
                                        cin.get();
                                        if (xy[1][1]==playerc)
                                        {
                                              if (xy[1][2]==playerc)
                                              {
                                                    if (xy[1][3]==playerc)
                                                    {
                                                          if (playerc=="x")
                                                          {
                                                                win = 2;
                                                          }
                                                          else if (playerc=="o")
                                                          {
                                                                win = 3;
                                                          }
                                                          else
                                                          {
                                                                win = 1;
                                                          }
                                                    }
                                                    else
                                                    {
                                                          win = 1;
                                                    }
                                              }
                                              else if (xy[2][1]==playerc)
                                              {
                                                    if (xy[3][1]==playerc)
                                                    {
                                                          if (playerc=="x")
                                                          {
                                                                win = 2;
                                                          }
                                                          else if (playerc=="o")
                                                          {
                                                                win = 3;
                                                          }
                                                          else
                                                          {
                                                                win = 1;
                                                          }
                                                    }
                                                    else
                                                    {
                                                          win = 1;
                                                    }
                                              }
                                              else if (xy[2][2]==playerc)
                                              {
                                                    if (xy[3][3]==playerc)
                                                    {
                                                          if (playerc=="x")
                                                          {
                                                                win = 2;
                                                          }
                                                          else if (playerc=="o")
                                                          {
                                                                win = 3;
                                                          }
                                                          else
                                                          {
                                                                win = 1;
                                                          }
                                                    }
                                                    else
                                                    {
                                                          win = 1;
                                                    }
                                              }
                                              else
                                              {
                                                    win = 1;
                                              }
                                        }
                                        else if (xy[2][1]==playerc)
                                        {
                                              if (xy[2][2]==playerc)
                                              {
                                                    if (xy[2][3]==playerc)
                                                    {
                                                          if (playerc=="x")
                                                          {
                                                                win = 2;
                                                          }
                                                          else if (playerc=="o")
                                                          {
                                                                win = 3;
                                                          }
                                                          else
                                                          {
                                                                win = 1;
                                                          }      
                                                    }
                                                    else
                                                    {
                                                          win = 1;
                                                    }
                                              }
                                              else
                                              {
                                                    win = 1;
                                              }
                                        }
                                        else if (xy[3][1]==playerc)
                                        {
                                              if (xy[3][2]==playerc)
                                              {
                                                    if (xy[3][3]==playerc)
                                                    {
                                                          if (playerc=="x")
                                                          {
                                                                win = 2;
                                                          }
                                                          else if (playerc=="o")
                                                          {
                                                                win = 3;
                                                          }
                                                          else
                                                          {
                                                                win = 1;
                                                          }
                                                    }
                                                    else
                                                    {
                                                          win = 1;
                                                    }
                                              }
                                              else if (xy[2][2]==playerc)
                                              {
                                                    if (xy[1][3]==playerc)
                                                    {
                                                          if (playerc=="x")
                                                          {
                                                                win = 2;
                                                          }
                                                          else if (playerc=="o")
                                                          {
                                                                win = 3;
                                                          }
                                                          else
                                                          {
                                                                win = 1;
                                                          }
                                                    }
                                                    else
                                                    {
                                                          win = 1;
                                                    }
                                              }
                                        }
                                        switch (win)
                                        {                        
                                              case 1:
                                                    player = 2;
                                                    break;
                                              case 2:
                                                    cout << "Congrats Player 1, you have won!";
                                                    RorQ();
                                                    break;
                                              default:
                                                    player = 2;
                                                    break;
                                        }
                                  }
                                  while (player==2)
                                  {
                                        playerc = "o";
                                        cout << "Player 2, enter the number of the row you wish to move to: ";
                                        cin >> x;
                                        cout << "Now enter the number of the column you wish to move to: ";
                                        cin >> y;
                                        xy[x][y]="o";
                                        system("pause");
                                        cout << "\t\t       1     2     3\n\n";
                                        cout << "\t\t          |     |     \n";
                                        cout << "\t\tA(1)   "<<xy[1][1]<<"  |  "<<xy[1][2]<<"  |  "<<xy[1][3]<<"  \n";
                                        cout << "\t\t     _____|_____|_____\n";
                                        cout << "\t\t          |     |     \n";
                                        cout << "\t\tB(2)   "<<xy[2][1]<<"  |  "<<xy[2][2]<<"  |  "<<xy[2][3]<<"  \n";
                                        cout << "\t\t     _____|_____|_____\n";
                                        cout << "\t\t          |     |     \n";
                                        cout << "\t\tC(3)   "<<xy[3][1]<<"  |  "<<xy[3][2]<<"  |  "<<xy[3][3]<<"  \n";
                                        cout << "\t\t          |     |     \n\n";
                                        if (xy[1][2]==playerc)
                                        {
                                              if (xy[1][3]==playerc)
                                              {
                                                    if (playerc=="x")
                                                    {
                                                          win = 2;
                                                    }
                                                    else if (playerc=="o")
                                                    {
                                                          win = 3;
                                                    }
                                                    else
                                                    {
                                                          win = 1;
                                                    }
                                              }
                                              else
                                              {
                                                    win = 1;
                                              }
                                        }
                                        else if (xy[2][1]==playerc)
                                        {
                                              if (xy[3][1]==playerc)
                                              {
                                                    if (playerc=="x")
                                                    {
                                                          win = 2;
                                                    }
                                                    else if (playerc=="o")
                                                    {
                                                          win = 3;
                                                    }
                                                    else
                                                    {
                                                          win = 1;
                                                    }
                                              }
                                              else
                                              {
                                                    win = 1;
                                              }
                                        }
                                        else if (xy[2][2]==playerc)
                                        {
                                              if (xy[3][3]==playerc)
                                              {
                                                    if (playerc=="x")
                                                    {
                                                          win = 2;
                                                    }
                                                    else if (playerc=="o")
                                                    {
                                                          win = 3;
                                                    }
                                                    else
                                                    {
                                                          win = 1;
                                                    }
                                              }
                                              else
                                              {
                                                    win = 1;
                                              }
                                        }
                                        else
                                        {
                                              win = 1;
                                        }
                                        if (xy[2][1]==playerc)
                                        {
                                              if (xy[2][2]==playerc)
                                              {
                                                    if (xy[2][3]==playerc)
                                                    {
                                                          if (playerc=="x")
                                                          {
                                                                win = 2;
                                                          }
                                                          else if (playerc=="o")
                                                          {
                                                                win = 3;
                                                          }
                                                          else
                                                          {
                                                                win = 1;
                                                          }      
                                                    }
                                                    else
                                                    {
                                                          win = 1;
                                                    }
                                              }
                                              else
                                              {
                                                    win = 1;
                                              }
                                        }
                                        else if (xy[3][1]==playerc)
                                        {
                                              if (xy[3][2]==playerc)
                                              {
                                                    if (xy[3][3]==playerc)
                                                    {
                                                          if (playerc=="x")
                                                          {
                                                                win = 2;
                                                          }
                                                          else if (playerc=="o")
                                                          {
                                                                win = 3;
                                                          }
                                                          else
                                                          {
                                                                win = 1;
                                                          }
                                                    }
                                                    else
                                                    {
                                                          win = 1;
                                                    }
                                              }
                                              else if (xy[2][2]==playerc)
                                              {
                                                    if (xy[1][3]==playerc)
                                                    {
                                                          if (playerc=="x")
                                                          {
                                                                win = 2;
                                                          }
                                                          else if (playerc=="o")
                                                          {
                                                                win = 3;
                                                          }
                                                          else
                                                          {
                                                                win = 1;
                                                          }
                                                    }
                                                    else
                                                    {
                                                          win = 1;
                                                    }
                                              }
                                        }
                                        switch (win)
                                        {                        
                                              case 1:
                                                    player = 1;
                                                    break;
                                              case 2:
                                                    cout << "Congrats Player 2, you have won!";
                                                    RorQ();
                                                    break;
                                              default:
                                                    player = 1;
                                                    break;
                                        }
                                  }
                            break;
                      case 3:
                            cout << "\t\tTic-Tac-Toe\n";
                            cout << "\t\tBy Michael Kylman\n\n";
                            cout << "Well, so far this game has no substance at all, it's just a menu!";
                            
                            system("pause");
                            RorQ();
                            break;
                      default:
                            cout << "Sorry thats an incorrect choice!" <<"\n";
                            RorQ();
                            break;
                      }
                      clrscr();
          }
                cin.get();
                return 0;
          }
    }
    void MENU() //Gives user the choice of what math option to make
    { 
          cout << "\n\n";
          cout << "\t\tMENU\n";
          cout << "0. EXIT GAME"<<"\n";                                 //Exits program
     cout << "1. 1 Player Game(Not Yet Functional)" <<"\n"; //Adds two numbers
     cout << "2. 2 Player Game"<<"\n";                         //Subtracts two numbers
     cout << "3. ABOUT" <<"\n";                                     //About the program
     cout << "Enter the number of your selection>";
          cin  >> C.menu;
          clrscr();
    }
    
    void EXIT()
    {
          cout << "Goodbye, Thanks for Playing!\n";
          C.exit=0;
    }
    
    void RorQ() //Gives user the option to restart or quit
    {
          clrscr();
          cout << "Press (r) to Return to the menu or (q) to Quit\n";
          cout << ">";
          cin  >> C.rq[1];
          cin.ignore();
    
          if(C.rq[1] == 'r')
          {
                clrscr();
                main();
          }
          else if(C.rq[1] == 'q')
          {
                EXIT();
          }
          else
          {
                cout << "Thats not a valid choice... Please rechoose" << "\n";
                RorQ();
          }
    }
    void clrscr() //Clears the screen
    {
        COORD coordScreen = { 0, 0 };
        DWORD cCharsWritten;
        CONSOLE_SCREEN_BUFFER_INFO csbi;
        DWORD dwConSize;
        HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        
        GetConsoleScreenBufferInfo(hConsole, &csbi);
        dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
        FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
        GetConsoleScreenBufferInfo(hConsole, &csbi);
        FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
        SetConsoleCursorPosition(hConsole, coordScreen);
    }
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  5. #5
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    Here is some of the errors:
    Code:
       string xy[3][3];
                string playerc;
                MENU();
                switch (C.menu) //A switch statement that chooses the math option
                {
                      xy[1][1]=" ";
                      xy[1][2]=" ";
                      xy[1][3]=" ";
                      xy[2][1]=" ";
                      xy[2][2]=" ";
                      xy[2][3]=" ";
                      xy[3][1]=" ";
                      xy[3][2]=" ";
                      ...
    Arrays are zero based. So it should be:
    Code:
       string xy[3][3];
                string playerc;
                MENU();
                switch (C.menu) //A switch statement that chooses the math option
                {
                      xy[0][0]=" ";
                      xy[0][1]=" ";
                      xy[0][2]=" ";
                      xy[1][0]=" ";
                      xy[1][1]=" ";
                      xy[1][2]=" ";
                      xy[2][0]=" ";
                      xy[2][1]=" ";
                      ...
    Use loops to fill such arrays.

    Put that splash screen and things like that in a function.
    Don't call main in other functions.
    Names like variable and C are useless and confuzing. Dont use such names.

    Correct these and we will help you correct other errors.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  6. #6
    Registered User
    Join Date
    Aug 2006
    Posts
    62
    thanks man; YOU ARE GOD!!! That worked, so I'm rather pleased with the program now...it needs some cleaning up, but it works; thanks man;

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    He must be god to be able to read that. Next time if it's over 50 or so lines, attach the cpp file to the post.

  8. #8
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    He must be god to be able to read that.
    The painted code is much easier to read. Especially when it bolds some known words like cout and main.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Just wait for codeform 1.20, which I'm writing right now . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me with my simple Tic tac toe prog
    By maybnxtseasn in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 06:25 PM
  2. Help with Tic Tac Toe game
    By snef73 in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2003, 08:33 AM
  3. Need some help with a basic tic tac toe game
    By darkshadow in forum C Programming
    Replies: 1
    Last Post: 05-12-2002, 04:21 PM
  4. tic tac toe game
    By Leeman_s in forum Game Programming
    Replies: 9
    Last Post: 04-24-2002, 03:24 AM
  5. my tic tac toe game, please try it
    By Leeman_s in forum C++ Programming
    Replies: 2
    Last Post: 04-14-2002, 05:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21