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