Hello,

I am working on this tic tac toe program for my computer science class to develop a tic tac toe game that uses artifical intelegence for a computer player. Anyway, I have a few question, help with any or all.

First, I am getting unresolved externals errors. I do not know how to find where these are in my program when I get them. So my first question is, and I am using microsoft visual C++ 6.0 as a compiler, how do I find where the unresolved externals are to fix them? Every time I ask my teacher, she just fixxes it for me, so I dont know how to find them myself.

Second, as we only learned functions 3 weeks ago, I am not quite sure I have properly used function declarations, function calls, and function defenitions. Any input on how I have used these?

Last, I can tell my compplay function is unnessecarily complex, it just repeats looking for X's then O's using the same code. How could I condense this to be more efficient.

As always, thanks a bunch. I really appriciate those who give there time helping new commers.

Attachments
#include <iostream>
using namespace std;
char box[9];
int round, win, compwin;
char stopcode;



void draw(char box [9]);
void pplay(char box [9]);
void compplay(char [9], int round);
void chkwin(char box [9], char z);


int main()
{
    do
    {
        round=win=compwin=0;
        for ( int i=0; i<9; i++)
			box[i]=1+i;
        draw(box);
        do
        {
			
            pplay(box);
            compplay (box, round);
            draw(box);
            chkwin(box, 'X');
            chkwin(box, '0');
			
			
        }while((round<4)&&(win==0));
        if (win==1)
        {
            if (compwin==1)
                cout<<"\n YOU WIN!!! ";
            else
                cout<<"\n THE COMPUTER WINS. YOU LOSE ";
        }
        if ((round>=4)&&(win==0))
            cout<<"\n It's a draw.";
        cout<<"\n Do you want to play another game?? Press Y";
        cin>>stopcode;
	}while((stopcode=='Y')||(stopcode=='y'));
	
	return 0;
}


void draw()
{
    cout<<"\n +---+---+---+";
    cout<<"\n | "<<box[0]<<" | "<<box[1]<<" | "<<box[2]<<" | ";
    cout<<"\n +---+---+---+";
    cout<<"\n | "<<box[3]<<" | "<<box[4]<<" | "<<box[5]<<" | ";
    cout<<"\n +---+---+---+";
    cout<<"\n | "<<box[6]<<" | "<<box[7]<<" | "<<box[8]<<" | ";
    cout<<"\n +---+---+---+";
}

void pplay(char box [9])
{
    int sq;
	bool repeat = false;
    cout<<"\n Enter the square number : ";
    do {
		cin>>sq;
		if ((sq>0)&&(sq<=9))
		{
			if (box[sq-1]==sq)
			{
				box[sq-1]='X';
				repeat = true;
			}
			else
			{
				cout<<"\n Enter an empty square number ";
			}
		}
		else
		{
			cout<<"\n Enter a valid square number(1-9) : ";
		}
	} while (repeat == true);
	
	
}

void compplay(char box [9], int round)
{
	int i,a;
	a=round;
	if (round==0)
	{
		if (box[4]!='X')
			box[4]='0';
		else
			box[8]='0';
		round++;
	}
	else
	{
		if (round==a)
		{
			for (i=0; i<7;i+=3)
			{
				if (round==a)
				{
					if (((box[i]=='X')&&(box[i+1]=='X'))&&((box[i+1]=='X')&&(box[i+2]==3+i)))
					{
						box[i+2]='0';
						round++;
					}
				}
				if (round==a)
				{
					if (((box[i+1]=='X')&&(box[i+2]=='X'))&&((box[i+2]=='X')&&(box[i]==4+i)))
					{
						box[i]='0';
						round++;
					}	
				}
				if (round==a)
				{
					if (((box[i]=='X')&&(box[i+2]=='X'))&&((box[i+2]=='X')&&(box[i+1]==5+i)))
					{
						box[i+1]='0';
						round++;
					}
				}
			}
		}
		if (round==a)
		{
			for (i=0; i<3;i++)
			{
				if (round==a)
				{
					if (((box[i]=='X')&&(box[i+3]=='X'))&&((box[i+3]=='X')&&(box[i+6]==7+i)))
					{
						box[i+6]='0';
						round++;
					}
				}
				if (round==a)
				{
					if (((box[i]=='X')&&(box[i+6]=='X'))&&((box[i+6]=='X')&&(box[i+3]==4+i)))
					{
						box[i+3]='0';
						round++;
					}
				}
				if (round==a)
				{
					if (((box[i+3]=='X')&&(box[i+6]=='X'))&&((box[i+6]=='X')&&(box[i]==1+i)))
					{
						box[i]='0';
						round++;
					}
				}
			}
		}
		if (round==a)
		{
			if (((box[0]=='X')&&(box[4]=='X'))&&((box[4]=='X')&&(box[8]==9)))
			{
				box[8]='0';
				round++;
			}
			else if (((box[4]=='X')&&(box[8]=='X'))&&((box[8]=='X')&&(box[0]==1)))
			{
				box[0]='0';
				round++;
			}
			else if (((box[0]=='X')&&(box[8]=='X'))&&((box[8]=='X')&&(box[4]==5)))
			{
				box[4]='0';
				round++;
			}
			
		}
		if (round==a)
		{
			if (((box[2]=='X')&&(box[4]=='X'))&&((box[4]=='X')&&(box[6]==7)))
			{
				box[6]='0';
				round++;
			}
			else if (((box[4]=='X')&&(box[6]=='X'))&&((box[6]=='X')&&(box[2]==3)))
			{
				box[2]='0';
				round++;
			}
			else if (((box[2]=='X')&&(box[6]=='X'))&&((box[6]=='X')&&(box[4]==6)))
			{
				box[8]='0';
				round++;
			}
		}
		if (round==a)
		{
			for (i=0; i<7;i+=3)
			{
				if (round==a)
				{
					if (((box[i]=='O')&&(box[i+1]=='O'))&&((box[i+1]=='O')&&(box[i+2]==3+i)))
					{
						box[i+2]='0';
						round++;
					}
				}
				if (round==a)
				{
					if (((box[i+1]=='O')&&(box[i+2]=='O'))&&((box[i+2]=='O')&&(box[i]==4+i)))
					{
						box[i]='0';
						round++;
					}	
				}
				if (round==a)
				{
					if (((box[i]=='O')&&(box[i+2]=='O'))&&((box[i+2]=='O')&&(box[i+1]==5+i)))
					{
						box[i+1]='0';
						round++;
					}
				}
			}
		}
		if (round==a)
		{
			for (i=0; i<3;i++)
			{
				if (round==a)
				{
					if (((box[i]=='O')&&(box[i+3]=='O'))&&((box[i+3]=='O')&&(box[i+6]==7+i)))
					{
						box[i+6]='0';
						round++;
					}
				}
				if (round==a)
				{
					if (((box[i]=='O')&&(box[i+6]=='O'))&&((box[i+6]=='O')&&(box[i+3]==4+i)))
					{
						box[i+3]='0';
						round++;
					}
				}
				if (round==a)
				{
					if (((box[i+3]=='O')&&(box[i+6]=='O'))&&((box[i+6]=='O')&&(box[i]==1+i)))
					{
						box[i]='0';
						round++;
					}
				}
			}
		}
		if (round==a)
		{
			if (((box[0]=='O')&&(box[4]=='O'))&&((box[4]=='O')&&(box[8]==9)))
			{
				box[8]='0';
				round++;
			}
			else
				if (((box[4]=='O')&&(box[8]=='O'))&&((box[8]=='O')&&(box[0]==1)))
				{
					box[0]='0';
					round++;
				}
				else
					if (((box[0]=='O')&&(box[8]=='O'))&&((box[8]=='O')&&(box[4]==5)))
					{
						box[4]='0';
						round++;
					}
		}
		if (round==a)
		{
			if (((box[2]=='O')&&(box[4]=='O'))&&((box[4]=='O')&&(box[6]==7)))
			{
				box[6]='0';
				round++;
			}
			else
				if (((box[4]=='O')&&(box[6]=='O'))&&((box[6]=='O')&&(box[2]==3)))
				{
					box[2]='0';
					round++;
				}
				else
					if (((box[2]=='O')&&(box[6]=='O'))&&((box[6]=='O')&&(box[4]==6)))
					{
						box[8]='0';
						round++;
					}
		}
		if(round==a)
		{
			
			for (i=0; i<9; i++)
			{	
				do{

					if ((box[i]!='X')&&(box[i]!='0'))
						{
							box[i]='0';
							round++;
						}
					
					} while (round == a);
			}
		}
    }
	
}	
void chkwin(char box [9], char z)
{
	
	for (int i=0; i<7; i+=3)
		if (((box[i]==z)&&(box[i+1]==z))&&((box[i+1]==z)&&(box[i+2]==z)))
		{ 
			win=1;
		}
		for (int j=0; j<3; j++)
			if (((box[j]==z)&&(box[j+3]==z))&&((box[j+3]==z)&&(box[j+6]==z)))
			{    
				win=1;
			}
			if (((box[0]==z)&&(box[4]==z))&&((box[4]==z)&&(box[8]==z)))
				win=1;
			if (((box[2]==z)&&(box[4]==z))&&((box[4]==z)&&(box[6]==z)))
				win=1;
			if ((win==1)&&(z=='X'))
				compwin=1;
}

First, I am getting unresolved externals errors. I do not know how to find where these are in my program when I get them. So my first question is, and I am using microsoft visual C++ 6.0 as a compiler, how do I find where the unresolved externals are to fix them? Every time I ask my teacher, she just fixxes it for me, so I dont know how to find them myself.

Make your prototypes match your definitions.

void draw(char box [9]);
void draw()

Second, as we only learned functions 3 weeks ago, I am not quite sure I have properly used function declarations, function calls, and function defenitions. Any input on how I have used these?

See previous.

Last, I can tell my compplay function is unnessecarily complex, it just repeats looking for X's then O's using the same code. How could I condense this to be more efficient.

You'll go far in programming.

I haven't looked very closely. But this exercise is more for you. Perhaps someone will provide a more specific hint.

This article has been dead for over six months. Start a new discussion instead.