Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,376 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,031 people online right now. Registration is fast and FREE... Join Now!




good old tic tac toe

 
Reply to this topicStart new topic

good old tic tac toe, you guessed it I need a little help with a T.T.T. program

MingusDew
29 Sep, 2006 - 06:32 AM
Post #1

New D.I.C Head
*

Joined: 28 Sep, 2006
Posts: 13


My Contributions
I got the base source code for this from http://www.bloodshed.net/c/index.html. What I did was take the source code and retyped it so I could get nitty gritty with the code. i can get it as far as compiling down to a .tds and .obj files but then it gives me a
CODE
Error: Unresolved external 'cou()' referenced from F:\BORLAND\BCC55\018E2.ODJ

Also there was a
CODE
Warning W8004 018e2.cpp: 'sum' is assigned a value that is never used in function main()

will this kind of warning actually affect the program adversely?

here's the code i have so far I think its exactly like the original, I've gone over with a line by line comparison at least thrice, which compiled fine hence the stop point in my learning to ask for help.
CODE

#include <iostream.h>
#include <stdlib.h>
#include <conio.h>

char matrix[3][3];//={0};

void cou(void);

int main()
{
  int m,n;
  char ch ='y';

  while(ch == 'y'||ch == 'y') {
    for (m=0;m<3;m++)for (n=0;n<3;n++)matrix[m][n]= '\0';
    int i,j,sum=0;

  while ( sum < 10) {
      if (sum == 0) cou();
      cout<<"Player 1 is 'X': Choose the Row and Column.\n";
      cout<<"Column :";
      cin>> j;
      cout<<"Row :";
      cin>> i;
      for (;i > 3 || i < 1 || j > 3 || j < 1 ||('X' == matrix[i-1][j-1]||'O' == matrix[i-1][j-1]);) {
      cout<<"Sorry there pal, you gotta pick another place.\n";
      cout<<"Column :";
      cin>> j;
      cout<<"Row :";
      cin>> i;
      }
    matrix[i-1][j-1]='X';
    sum++;
    cou();

    if ( matrix[0][0] == 'X'  &&  matrix[0][0] == matrix[1][1]  &&  matrix[1][1] == matrix[2][2] )  {cout<<"Player 1 wins.";break; }
    if ( matrix[0][1] == 'X'  &&  matrix[0][1] == matrix[1][1]  &&  matrix[1][1] == matrix[2][1] )  {cout<<"Player 1 wins.";break; }
    if ( matrix[2][0] == 'X'  &&  matrix[2][0] == matrix[1][1]  &&  matrix[1][1] == matrix[0][2] )  {cout<<"Player 1 wins.";break; }
    if ( matrix[2][1] == 'X'  &&  matrix[2][1] == matrix[1][1]  &&  matrix[1][1] == matrix[0][1] )  {cout<<"Player 1 wins.";break; }
    if ( matrix[2][2] == 'X'  &&  matrix[2][2] == matrix[2][1]  &&  matrix[2][1] == matrix[2][0] )  {cout<<"Player 1 wins.";break; }
    if ( matrix[0][2] == 'X'  &&  matrix[0][2] == matrix[0][1]  &&  matrix[0][1] == matrix[0][0] )  {cout<<"Player 1 wins.";break; }
    if ( matrix[0][0] == 'X'  &&  matrix[0][0] == matrix[1][0]  &&  matrix[1][0] == matrix[2][0] )  {cout<<"Player 1 wins.";break; }
    if ( matrix[0][2] == 'X'  &&  matrix[0][2] == matrix[1][2]  &&  matrix[1][2] == matrix[2][2] )  {cout<<"Player 1 wins.";break; }
    
  if ( sum == 9 ) {
      cout<<"The game is over and no one wins, hahaha, you both stink!!!\n";
//player 2's turn
  
      cout<<"Player 2 is 'O': Choose the Row and Column.\n";
      cout<<"Column :";
      cin>> j;
      cout<<"Row :";
      cin>> i;
      for (;i > 3 || i < 1 || j > 3 || j < 1 ||('x'==matrix[i-1][j-1]||'o'==matrix[i-1][j-1]);) {
        matrix[i-1][j-1]='X';
        sum++;
        cou();
        if ( matrix[0][0] == 'O'  &&  matrix[0][0] == matrix[1][1]  &&  matrix[1][1] == matrix[2][2] )  {cout<<"Player 1 wins.";break; }
        if ( matrix[0][1] == 'O'  &&  matrix[0][1] == matrix[1][1]  &&  matrix[1][1] == matrix[2][1] )  {cout<<"Player 1 wins.";break; }
        if ( matrix[2][0] == 'O'  &&  matrix[2][0] == matrix[1][1]  &&  matrix[1][1] == matrix[0][2] )  {cout<<"Player 1 wins.";break; }
        if ( matrix[2][1] == 'O'  &&  matrix[2][2] == matrix[2][1]  &&  matrix[2][1] == matrix[2][0] )  {cout<<"Player 1 wins.";break; }
        if ( matrix[2][2] == 'O'  &&  matrix[2][2] == matrix[2][1]  &&  matrix[2][1] == matrix[2][0] )  {cout<<"Player 1 wins.";break; }
        if ( matrix[0][2] == 'O'  &&  matrix[0][2] == matrix[0][1]  &&  matrix[0][1] == matrix[0][0] )  {cout<<"Player 1 wins.";break; }
        if ( matrix[0][0] == 'O'  &&  matrix[0][0] == matrix[1][0]  &&  matrix[1][0] == matrix[2][0] )  {cout<<"Player 1 wins.";break; }
        if ( matrix[0][2] == 'O'  &&  matrix[0][2] == matrix[1][2]  &&  matrix[1][2] == matrix[2][2] )  {cout<<"Player 1 wins.";break; }
        }
  cout<<"Would like to play Another game??? ( y - n )\n";
  cin>>ch;
      }
    system("PAUSE");
  return 0;
    }


void cou(void);
  cout<<"\n";
  cout<<"\n";
  cout<<"\t\t               1   2   3\n";
  cout<<"\t\t             1 "<< matrix[0][0]<<" | "<< matrix[1][0]<<" | "<< matrix[2][0]<<"\n";
  cout<<"\t\t              --|--|--\n";
  cout<<"\t\t             2 "<< matrix[0][1]<<" | "<< matrix[1][1]<<" | "<< matrix[2][1]<<"\n";
  cout<<"\t\t              --|--|--\n";
  cout<<"\t\t             3 "<< matrix[0][2]<<" | "<< matrix[1][2]<<" | "<< matrix[2][2]<<"\n\n\n";
  };
}


if you want me to paste the original .cpp file I can do that too, I'll continue working on it too.

if you dont think I should post nearly complete code or complete code, so that people can learn more, please let me know.

any help on this project is greatly appreciated

Peace
User is offlineProfile CardPM
+Quote Post

DeeViLiSh
RE: Good Old Tic Tac Toe
29 Sep, 2006 - 12:30 PM
Post #2

D.I.C Head
Group Icon

Joined: 25 Jul, 2006
Posts: 175



Thanked: 1 times
Dream Kudos: 575
My Contributions
I already see some errors with the cou declaration at the end, I'm downloading Code::Blocks and then I'll point some of the problems and perhaps fix your problem ^^
User is offlineProfile CardPM
+Quote Post

Mrafcho001
RE: Good Old Tic Tac Toe
29 Sep, 2006 - 12:44 PM
Post #3

D.I.C Addict
Group Icon

Joined: 1 Nov, 2005
Posts: 753



Thanked: 5 times
Dream Kudos: 120
My Contributions
CODE
char matrix[3][3];//={0};

not the same as:
CODE
char matrix[3][3] = {0};


You guys are sooo bad. There is probably over 100 threads about TTT already. Why don't you just search?

and obviously you suck really bad if you dont know how to properly declare and define a function:

CODE

void foo();//declaration
...
void foo(){
}//definition


Go back and learn the stuff before diving into something of this size.
User is offlineProfile CardPM
+Quote Post

DeeViLiSh
RE: Good Old Tic Tac Toe
29 Sep, 2006 - 01:19 PM
Post #4

D.I.C Head
Group Icon

Joined: 25 Jul, 2006
Posts: 175



Thanked: 1 times
Dream Kudos: 575
My Contributions
CODE
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>

char matrix[3][3];

void cou(void);

int main()
{
  int m,n;
  char ch ='y';

  while(ch == 'y'||ch == 'y')
  {
         for (m=0;m<3;m++)
                  for (n=0;n<3;n++)matrix[m][n]= '\0';
                  int i,j,sum=0;

         while ( sum < 10)
         {
                  if (sum == 0)
                           cou();

                  cout<<"Player 1 is 'X': Choose the Row and Column.\n";
                  cout<<"Column :";
                  cin>> j;
                  cout<<"Row :";
                  cin>> i;

                  for (;i > 3 || i < 1 || j > 3 || j < 1 ||('X' == matrix[i-1][j-1]||'O' == matrix[i-1][j-1]);)
                  {
                           cout<<"Sorry there pal, you gotta pick another place.\n";
                           cout<<"Column :";
                           cin>> j;
                           cout<<"Row :";
                           cin>> i;
                  }

                  matrix[i-1][j-1]='X';
                  sum++;
                  cou();

                  if ( matrix[0][0] == 'X'  &&  matrix[0][0] == matrix[1][1]  &&  matrix[1][1] == matrix[2][2] )
                  {cout<<"Player 1 wins.";break; }

                  if ( matrix[0][1] == 'X'  &&  matrix[0][1] == matrix[1][1]  &&  matrix[1][1] == matrix[2][1] )
                  {cout<<"Player 1 wins.";break; }

                  if ( matrix[2][0] == 'X'  &&  matrix[2][0] == matrix[1][1]  &&  matrix[1][1] == matrix[0][2] )
                  {cout<<"Player 1 wins.";break; }

                  if ( matrix[2][1] == 'X'  &&  matrix[2][1] == matrix[1][1]  &&  matrix[1][1] == matrix[0][1] )
                  {cout<<"Player 1 wins.";break; }

                  if ( matrix[2][2] == 'X'  &&  matrix[2][2] == matrix[2][1]  &&  matrix[2][1] == matrix[2][0] )
                  {cout<<"Player 1 wins.";break; }

                  if ( matrix[0][2] == 'X'  &&  matrix[0][2] == matrix[0][1]  &&  matrix[0][1] == matrix[0][0] )
                  {cout<<"Player 1 wins.";break; }

                  if ( matrix[0][0] == 'X'  &&  matrix[0][0] == matrix[1][0]  &&  matrix[1][0] == matrix[2][0] )
                  {cout<<"Player 1 wins.";break; }

                  if ( matrix[0][2] == 'X'  &&  matrix[0][2] == matrix[1][2]  &&  matrix[1][2] == matrix[2][2] )
                  {cout<<"Player 1 wins.";break; }

                  if ( sum == 9 )
                  {
                            cout<<"The game is over and no one wins, hahaha, you both stink!!!\n";
                           //player 2's turn

                           cout<<"Player 2 is 'O': Choose the Row and Column.\n";
                           cout<<"Column :";
                           cin>> j;
                           cout<<"Row :";
                           cin>> i;

                           for (;i > 3 || i < 1 || j > 3 || j < 1 ||('x'==matrix[i-1][j-1]||'o'==matrix[i-1][j-1]);)
                           {
                                    matrix[i-1][j-1]='X';
                                    sum++;
                                    cou();
                                    if ( matrix[0][0] == 'O'  &&  matrix[0][0] == matrix[1][1]  &&  matrix[1][1] == matrix[2][2] )  {cout<<"Player 1 wins.";break; }
                                    if ( matrix[0][1] == 'O'  &&  matrix[0][1] == matrix[1][1]  &&  matrix[1][1] == matrix[2][1] )  {cout<<"Player 1 wins.";break; }
                                    if ( matrix[2][0] == 'O'  &&  matrix[2][0] == matrix[1][1]  &&  matrix[1][1] == matrix[0][2] )  {cout<<"Player 1 wins.";break; }
                                    if ( matrix[2][1] == 'O'  &&  matrix[2][2] == matrix[2][1]  &&  matrix[2][1] == matrix[2][0] )  {cout<<"Player 1 wins.";break; }
                                    if ( matrix[2][2] == 'O'  &&  matrix[2][2] == matrix[2][1]  &&  matrix[2][1] == matrix[2][0] )  {cout<<"Player 1 wins.";break; }
                                    if ( matrix[0][2] == 'O'  &&  matrix[0][2] == matrix[0][1]  &&  matrix[0][1] == matrix[0][0] )  {cout<<"Player 1 wins.";break; }
                                    if ( matrix[0][0] == 'O'  &&  matrix[0][0] == matrix[1][0]  &&  matrix[1][0] == matrix[2][0] )  {cout<<"Player 1 wins.";break; }
                                    if ( matrix[0][2] == 'O'  &&  matrix[0][2] == matrix[1][2]  &&  matrix[1][2] == matrix[2][2] )  {cout<<"Player 1 wins.";break; }
                           }

                           cout<<"Would like to play Another game??? ( y - n )\n";
                           cin>>ch;
                  }

         }


  }
   system("PAUSE");
    return 0;
}

void cou(void)
{
  cout<<"\n";
  cout<<"\n";
  cout<<"\t\t               1   2   3\n";
  cout<<"\t\t             1 "<< matrix[0][0]<<" | "<< matrix[1][0]<<" | "<< matrix[2][0]<<"\n";
  cout<<"\t\t              --|--|--\n";
  cout<<"\t\t             2 "<< matrix[0][1]<<" | "<< matrix[1][1]<<" | "<< matrix[2][1]<<"\n";
  cout<<"\t\t              --|--|--\n";
  cout<<"\t\t             3 "<< matrix[0][2]<<" | "<< matrix[1][2]<<" | "<< matrix[2][2]<<"\n\n\n";
}


Main problems were :
    Not clear and easy to read
    Semi colons not finished
    You added a coma after the void cou() at the end
After you declared your function before int main();
you consider
CODE
void cou()
{
//code
}

a whole different body.

This post has been edited by DeeViLiSh: 29 Sep, 2006 - 01:21 PM
User is offlineProfile CardPM
+Quote Post

MingusDew
RE: Good Old Tic Tac Toe
29 Sep, 2006 - 10:21 PM
Post #5

New D.I.C Head
*

Joined: 28 Sep, 2006
Posts: 13


My Contributions
Ok first of all thank you for the feedback I will take it all into careful consideration.
second of all I searched, a few different ways, for tic tac toe thread, and I was very disspleased not have found anything but a error message about the keywords bieng under 4 characters long. I was especially displeased since I have read one of the TTT posts myself. And yes I can agree that I do suck, though not by not trying but for lack of experience <1 month programming experience, this is the first language I've tried to learn WEEEE. But yeah I found the problems and they are fixed now. Anyway thank you especially you DeeViLiSh for being as helpful as you were. I'll get better at doing this I swear.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 01:41AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month