I'm a beginner at c++ and I have to do a game of tic tac toe and I'm having problems with asking the player to play. Please help.
*****************************************************
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
///function prototype
void inttableArray(int [][3], int );
void displayArray (int [][3], int );
void inputArrayFunction(int [][3], int );
void getMove(int [][3], int );
void getComputerMove(int [][3], int );
char Check(int [][3], int );
int main()
{
char end;
end= ' ';
int tableOne[3][3]; //array of 3 row and 5 columns
cout<<"This is the game of Tic Tac Toe.\n";
cout<<"You will be playing against the computer.\n";
inttableArray(tableOne, 3);
displayArray(tableOne, 3);
getMove(tableOne, 3);
end = Check(tableOne, 3);
getComputerMove(tableOne, 3);
inputArrayFunction(tableOne, 3);
if(end== ' ');
if(end=='X') cout<<"You won!";
else cout<<"I won!!!!";
displayArray(tableOne, 3);
return 1;
}
//**************************************************
void inttableArray(int TempArray[][3], int size )
{
int row, column;
for ( row = 0; row <3; row ++)
for (column = 0; column < size; column ++)
TempArray[row][column] = ' ';
}
//**************************************************
void getMove(int TTempArray[][3], int Tsize)
{
int x =0;
int y=0;
int n=0;
cout<<" Please make your move: ";
cin>>n;
if(n<1||n>9)
cout<<"Invalid move"<<endl;
else
if(TTempArray[x][y]!= ' ')
{
cout<<"Invalid move, try again.\n";
getMove(TTempArray, 3);
}
else TTempArray[x][y] = 'X';
}
//**************************************************
void getComputerMove(int STempArray[][3], int Ssize)
{
int x;
int y;
int n;
cout<<"Player 2"<<endl;
cout<<" Please make your move: ";
cin>>n;
if(n<1||n>9)
cout<<"Invalid move"<<endl;
else
if(n=' ';n<=9);
if(STempArray[y][x]!= ' ')
{
cout<<"Invalid move, try again.\n";
getMove(STempArray, 3);
}
else STempArray[y][x] = 'Y';
}
//**************************************************
void displayArray (int DTempArray[][3], int Dsize)
{
int x=0;
int y=0;
for ( x = 0; x < 3; x ++)
{
printf(" %c | %c | %c ",DTempArray[x][0],
DTempArray[x][1], DTempArray [x][2]);
if(x!=2) printf("\n---|---|---\n");
}
printf("\n");
}
//**************************************************
void inputArrayFunction(int inputArray[][3], int inputsize)
{
int a, b;
int x = 1;
printf("\n---|---|---\n");
for ( a = 0 ;a < 3; a++)
for (b = 0; b < inputsize; b++)
if ( b == 2 )
inputArray[a][b] = 10;
else
inputArray[a][b] = b;
}
//**************************************************
char Check(int TinputArray[][3], int Tinputsize )
{
int i;
int row;
int tableOne[3][3];
for ( row = 0; row <3; row ++)
if(tableOne[row][0]==tableOne[row][1] &&
tableOne[row][0]==tableOne[row][2]) return tableOne[row][0];
for(i=0; i<3; i++)
if(tableOne[0][row]==tableOne[1][row] &&
tableOne[0][row]==tableOne[2][row]) return tableOne[0][row];
if(tableOne[0][0]==tableOne[1][1] &&
tableOne[1][1]==tableOne[2][2])
return tableOne[0][0];
if(tableOne[0][2]==tableOne[1][1] &&
tableOne[1][1]==tableOne[2][0])
return tableOne[0][2];
return ' ';
}