Hey all, this is my first post on this forum. I have been trolling around for a while though. Anyways, I was wondering if anybody could correct my code or point me in the right direction. My code below results in the errors listed after my code. Any help would be appreciated.
Thankyou
//Include the following libraries:
#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <cstdlib>
#include <ctime>
//Using the standard namespace
using namespace std;
class TicTacToe
{
private:
char TheBoard [3][3]; //Variable
int board [3][3];
//Explain to user what this program will do, and prompt for first move.
cout<<"This program plays Tic-Tac-Toe, and determines whether the game has concluded."<<endl;
cout<<"Please select a location for your first X."<<endl;
//Instruct the console to remain open
_getch();
return 0;
}
//Beginning of new Void Fuction TicTacToe, which is the fuction at the heart of the tic-tac-toe game.
void TicTacToe ::PlayOne (void)
{
//Declare the following local variables within fuction TicTacToe
const int MaxMoves=9;
char CurrentPlayer='O';
int row= 0;
int clmn= 0;
char TheWinner= ' ';
int NumMoves= 0;
//Utilizing the do while repitition structure
do {
SwitchPlayer (CurrentPlayer);
ShowBoard ();
//Prompt the user to input their moves and input into the console via CIN
cout<<"\n\n Player "<<CurrentPlayer<<endl;
cout<<"Enter Your Row (0, 1, 2): ";
cin>>row;
cout<<"Enter Your Column (0, 1, 2): ";
cin>>clmn;
//Post the Move To The Board
PostMove (row, clmn, CurrentPlayer);
//Determine if the game has a winner yet
TheWinner=Winner ();
//Keep Track of the Number of Moves
NumMoves++;
}
while ((Winner=='D')&&(NumMoves < MaxMoves));
//Shows the Ending Board
ShowBoard ();
if (Winner != 'D')
cout<<"\n\nThe Winner is Player: "<<Winner;
else
cout<<"\n\nThe Game Was a Draw: "<<endl;
class TicTacToe
{
private:
char TheBoard [3][3]; //Variable
int board [3][3];
public:
TicTacToe();
void PlayOne ();
void SwitchPlayer (char &);
void ShowBoard ();
void PostMove (int, int, char);
char Winner ();
//char determineWinner (); <- need to add this function or change the name to Winner
};
That should fix all of the "error C2065: 'TheBoard' : undeclared identifier" errors, after you fix that post the errors you have left
also use [code] tags or i wont reply next time, its hard as hell to read that code
//Using the standard namespace
usingnamespace std;
//Declare the following variables
char TheBoard [3][3];
int board [3][3];
void PlayOne ();
void SwitchPlayer (char &);
void ShowBoard ();
void PostMove (int, int, char);
char Winner ();
char determineWinner ();
char CurrentPlayer='O';
//Beginning of new Void Fuction TicTacToe, which is the fuction at the heart of the tic-tac-toe game.
void PlayOne ()
{
//Declare the following local variables
constint MaxMoves=9;
int row= 0;
int clmn= 0;
char TheWinner= ' ';
int NumMoves= 0;
//Utilizing the do while repitition structure
do
{
SwitchPlayer (CurrentPlayer);
ShowBoard ();
//Prompt the user to input their moves and input into the console via CIN
cout<<"\n\n Player "<<CurrentPlayer<<endl;
cout<<"Enter Your Row (0, 1, 2): ";
cin>>row;
cout<<"Enter Your Column (0, 1, 2): ";
cin>>clmn;
//Post the Move To The Board
PostMove (row, clmn, CurrentPlayer);
//Determine if the game has a winner yet
TheWinner=Winner() ;
//Keep Track of the Number of Moves
NumMoves++;
}
while ((Winner()=='D')&&(NumMoves < MaxMoves));
//Shows the Ending Board
ShowBoard ();
if (Winner() != 'D')
cout<<"\n\nThe Winner is Player: "<<Winner;
else
cout<<"\n\nThe Game Was a Draw: "<<endl;
}
//Initialize the array contents
void TicTacToe ()
{
TheBoard [3][3]=' ';
}
//Switches The Current Plater
void SwitchPlayer(char &tPlayer)
{
CurrentPlayer= ' ';
if (CurrentPlayer =='X')
{
cout << "\nPlayer 1: Make your move " ;
CurrentPlayer = 1;
}
else
(CurrentPlayer == 'X');
}
//Displays the Board to the user
void ShowBoard ()
{
cout<< "\n|"<<TheBoard [0][0]<<"|"<<TheBoard [0][1]<<"|"<<TheBoard [0][2]<<endl;
cout << "--------------------" << endl;
cout << "|" << TheBoard[1][0] << "|" << TheBoard[1][1] << "|" << TheBoard[1][2] << endl;
cout << "--------------------" << endl;
cout << "|" << TheBoard[2][0] << "|" << TheBoard[2][1] << "|" << TheBoard[2][2] << endl;
}
//Accepts move from the user and posts to the board
void postMove(int row, int clmn, char value)
{
char CurrentPlayer = ' ';
if (TheBoard[row][clmn]== 1|| TheBoard[row][clmn]==2)
{
cout << "Space already taken. Please choose another. " << endl;
}
else
{
TheBoard[row][clmn]=CurrentPlayer;
}
for(row = 0; row <3; row ++)
{
if(row > 3)
{
cout << "Invalid choice" << endl;
}
for(clmn = 0; clmn <3; clmn++)
{
if(clmn > 3)
{
cout << "Invalid choice" << endl;
}
if(TheBoard[row][clmn]==0)
{
TheBoard[row][clmn]=' ';
}
if (TheBoard[row][clmn]== 1)
{
TheBoard[row][clmn] = 'X';
}
if (TheBoard[row][clmn]== 2)
{
TheBoard[row][clmn] = 'O';
}
}
}
}
//Analyzes the board to determine if there is a winner, and returns X, O, or D (Draw)
char determineWinner()
{
//Checks the rows
for (int i = 0; i < 3; i++)
{
if (TheBoard[i][0] == TheBoard[i][1]
&& TheBoard[i][1] == TheBoard[i][2]
&& TheBoard[i][0] != ' ')
{
return TheBoard[i][0];
}
}
//Checks the Columns
for (int i = 0; i < 3; i++)
{
if (TheBoard[0][i] == TheBoard[1][i]
&& TheBoard[1][i] == TheBoard[2][i]
&& TheBoard[0][i] != ' ')
{
return TheBoard[0][i];
}
}
//Check to see if diagonal moves indicate a winner
if (TheBoard[0][0] == TheBoard[1][1]
&& TheBoard[1][1] == TheBoard[2][2]
&& TheBoard[0][0] != ' ')
{
return TheBoard[0][0];
}
if (TheBoard[2][0] == TheBoard[1][1]
&& TheBoard[1][1] == TheBoard[0][2]
&& TheBoard[2][0] != ' ')
{
return TheBoard[2][0];
}
return'D';
}
int _tmain(int argc, _TCHAR* argv[])
{
//Call the following functions to run
PlayOne ();
//Explain to user what this program will do, and prompt for first move.
cout<<"This program plays Tic-Tac-Toe, and determines whether the game has concluded."<<endl;
cout<<"Please select a location for your first X."<<endl;
//Instruct the console to remain open
_getch();
return 0;
}
When run, I encounter the following 3 errors :
Error1 error LNK2019: unresolved external symbol "char __cdecl Winner(void)" (?Winner@@YADXZ) referenced in function "void __cdecl PlayOne(void)" (?PlayOne@@YAXXZ) E:\Final_Project\Final_Project\Final_Project.obj Final_Project
Error 2 error LNK2019: unresolved external symbol "void __cdecl PostMove(int,int,char)" (?PostMove@@YAXHHD@Z) referenced in function "void __cdecl PlayOne(void)" (?PlayOne@@YAXXZ) E:\Final_Project\Final_Project\Final_Project.obj Final_Project