okay so the problem is that for some reason, z never becomes anything other than 1 because it keeps saying it is player ones turn.
also,
Code:
if(z==1) //if its player 1's turn
{
cout << p1 << ", enter your choice:" << endl << endl;
cout << "Row: ";
cin >> row; //input for row
cout << endl << "Coulumn: ";
cin >> col; //input for column
arr[row+1][col+1]='X'; //puts an X in the spot the user wants
}
shouldnt that change that row and column to X, all it does is reprints the
- - -
- - -
- - -
each time and it never changes
this is the latest version at this point:
Code:
//Dan Kemper ([email protected])
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
const int MAXROW = 3;
const int MAXCOL = 3;
void intro();
int main()
{
system("color 0f");
//declare variables
int k=0, j=0, z=1, row=0, col=0, win=0;
int input=0;
char p1[40],p2[40];
//initialize array
char arr[MAXROW][MAXCOL] =
{
{ '-', '-', '-', },
{ '-', '-', '-', },
{ '-', '-', '-', }
};
intro();
cout << "Press a key to continue...";
getch();
system("cls");
//user input for names
cout << "Player 1, enter your name: ";
cin.get(p1,40);
cin.ignore(80,'\n');
cout << "\n\nPlayer 2, enter your name: ";
cin.get(p2,40);
cin.ignore(80,'\n');
cout << "\n\nPress a key to continue...";
getch();
system("cls");
while(1) //main loop; looks like infinate but is later broken using break;
{
while(z<=2) //internal loop
{
//prints out array
for (k = 0; k < MAXROW; k++)
{
for (j = 0; j < MAXCOL; j++)
{
cout << "\t\t" << arr[k][j] << " ";
}
cout << endl << endl;
}
if(z==1) //if its player 1's turn
{
cout << endl << p1 << ", enter your choice:" << endl << endl;
cout << "Row: ";
cin >> row; //input for row
cout << endl << "Coulumn: ";
cin >> col; //input for column
arr[row+1][col+1]='X'; //puts an X in the spot the user wants
}
else //if player 2's turn
{
cout << endl << p1 << ", enter your choice:" << endl << endl;
cout << "Row: ";
cin >> row; //input for row
cout << endl << "Coulumn: ";
cin >> col; //input for column
arr[row+1][col+1]='O'; //puts an O in the spot the user wants
}
z++; //increments variable which control which persons turn it is
system("cls");
/* decides if player 1 wins */
if(arr[0][0]=='X' && arr[0][1]=='X' && arr[0][2]=='X')
{
cout << endl << p1 << " wins!!!";
z=-1;
break;
}
if(arr[1][0]=='X' && arr[1][1]=='X' && arr[1][2]=='X')
{
cout << endl << p1 << " wins!!!";
z=-1;
break;
}
if(arr[2][0]=='X' && arr[2][1]=='X' && arr[2][2]=='X')
{
cout << endl << p1 << " wins!!!";
z=-1;
break;
}
if(arr[0][0]=='X' && arr[1][1]=='X' && arr[2][2]=='X')
{
cout << endl << p1 << " wins!!!";
z=-1;
break;
}
if(arr[0][2]=='X' && arr[1][1]=='X' && arr[2][0]=='X')
{
cout << endl << p1 << " wins!!!";
z=-1;
break;
}
/* decides if player 2 wins */
if(arr[0][0]=='O' && arr[0][1]=='O' && arr[0][2]=='O')
{
cout << endl << p2 << " wins!!!";
z=-1;
break;
}
if(arr[1][0]=='O' && arr[1][1]=='O' && arr[1][2]=='O')
{
cout << endl << p2 << " wins!!!";
z=-1;
break;
}
if(arr[2][0]=='O' && arr[2][1]=='O' && arr[2][2]=='O')
{
cout << endl << p2 << " wins!!!";
z=-1;
break;
}
if(arr[0][0]=='O' && arr[1][1]=='O' && arr[2][2]=='O')
{
cout << endl << p2 << " wins!!!";
z=-1;
break;
}
if(arr[0][2]=='O' && arr[1][1]=='O' && arr[2][0]=='O')
{
cout << endl << p2 << " wins!!!";
z=-1;
break;
}
}
if(z==-1)
{
break;
}
z=1;
}
system("cls");
cout << "Press ESC to exit...";
while(input!=27)
{
input=getch();
}
return 0;
}
void intro()
{
int i=1;
while(i<=11)
{
switch(i)
{
case 1: cout << "T"; break;
case 2: cout << "i"; break;
case 3: cout << "c"; break;
case 4: cout << "-"; break;
case 5: cout << "T"; break;
case 6: cout << "a"; break;
case 7: cout << "c"; break;
case 8: cout << "-"; break;
case 9: cout << "T"; break;
case 10: cout << "o"; break;
case 11: cout << "e"; break;
}
Sleep(500);
i++;
}
cout << endl << endl;
}
after i get these things working i will douser proofing on what they can enter for rows and colums and add some colors like make the x's red and o's blue or sumthin...