new to c++ and VC++ express with linker errors

Hey all,

hope everyone is well...I am trying to type in a program from a book I am reading. the problem is I have the code in exactly as it is in the book but I still get errors when I try to compile. well no so much in the compiling process but in the 'linker'. I am no experienced enough to figure it out on my own so I was hoping for some help.

the following is the code (it's a console tic-tac-toe game)

// hi2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

const char X = 'X';
const char O = 'O';
const char EMPTY = ' ';
const char TIE = 'T';
const char NO_ONE = 'N';

void instructions();
char askYesNo(string question);
int askNumber(string question, int high, int low = 0);
char humanPiece();
char opponent(char piece);
void displayBoard(const vector<char>& board);
char winner(const vector<char>& board);
bool isLegal(const vector<char>& board, int move);
int humanMove(const vector<char>& board, char human);
int computerMove(const vector<char>& board, char computer);
void announceWinner(char winner, char computer, char human);

int main()
{
int move;
const int NUM_SQUARES = 9;
vector<char> board(NUM_SQUARES, EMPTY);

instructions();
char human = humanPiece();
char computer = opponent(human);
char turn = X;
displayBoard(board);

while (winner(board) == NO_ONE)
{
if (turn == human)
{
move = humanMove(board, human);
board[move] = human;
}
else
{
move = computerMove(board,computer);
board[move] = computer;
}
displayBoard(board);
turn = opponent(turn);
}
announceWinner(winner(board), computer, human);

return 0;

}

void instructions()
{
cout << "Welcome to the ultimate man-machine showdown: Tic-Tac-Toe.\n";
cout << "--where human brain is pit against silicon processor\n\n";

cout << "Make your move known by entering a number, 0 - 8. The number\n";
cout << "corresponds to the desired board position, as illustrated:\n\n";

cout << " 0 | 1 | 2\n";
cout << " _________\n";
cout << " 3 | 4 | 5\n";
cout << " _________\n";
cout << " 6 | 7 | 8\n";

cout << "Prepare yourself, human. the battle is about to begin.\n\n";
}
char askYesNo(string question)
{
char response;
do
{
cout << question << " (y/n): ";
cin >> response;
} while (response != 'y' && response != 'n');

return response;
}

int askNumber(string question, int high, int low)
{
int number;
do
{
cout << question << " ( " << low << " - " << high << "): ";
cin >> number;
} while (number > high || number < low);
return number;
}


char humanPiece()
{
char go_first = askYesNo("Do you require the first move ");
if (go_first == 'y')
{
cout << "\nThen take the first move. You will need it.\n";
return X;
}
else
{
cout << "\nYou bravery will be your undoing...I will go first.\n";
return 0;
}
}

char oppenent(char piece)
{
if (piece == X)
return O;
else
return X;
}

void displayBoard(const vector<char>& board)
{
cout << "\n\t" << board[0] << " | " << board[1] << " | " << board[2];
cout << "\n\t" << "_________";
cout << "\n\t" << board[3] << " | " << board[4] << " | " << board[5];
cout << "\n\t" << "_________";
cout << "\n\t" << boardDevil << " | " << board[7] << " | " << boardMusic;
}

char winner(const vector<char>& board)
{
const int WINNING_ROWSMusic[3] = { {0,1,2},
{3,4,5},
{6,7,8},
{1,4,7},
{0,3,6},
{2,5,8},
{2,4,8},
{2,4,6}};

const int TOTAL_ROWS = 8;

for(int row = 0; row < TOTAL_ROWS; ++row)
{
if((board[WINNING_ROWS[row][0]] != EMPTY) &&
(board[WINNING_ROWS[row][0]] == board[WINNING_ROWS[row][1]]) &&
(board[WINNING_ROWS[row][1]] == board[WINNING_ROWS[row][2]]))
{
return board[WINNING_ROWS[row][0]];
}
}

if (count(board.begin(), board.end(), EMPTY) == 0)
return TIE;

return NO_ONE;
}

inline bool isLegal(int move, const vector<char>& board)
{
return (board[move] == EMPTY);
}


int humanMove(const vector<char>& board, char human)
{
int move = askNumber("Where will you move " , (board.size() - 1));
while (!isLegal(move, board))
{
cout << "\nThe square is already occupied, meatbag.\n";
move = askNumber("Where will you move ", (board.size()-1));
}
cout << "Fine...\n";
return move;
}

int computerMove(vector<char> board, char computer)
{
cout << "I shall take square number ";

for (int move = 0; move < board.size(); ++move)
{
if (isLegal(move, board))
{
board[move] = computer;
if (winner(board) == computer)
{
cout << move << endl;
return move;
}

board[move] = EMPTY;
}
}

char human = opponent(computer);

for (int move = 0; move < board.size(); ++move)
{
if (isLegal(move, board))
{
board[move]=human;
if (winner(board) == human)
{
cout << move << endl;
return move;
}
board[move] = EMPTY;
}
}

const int BEST_MOVES[] = {4,0,2,6,8,1,3,5,7};
for(int i = 0; i < board.size(); ++i)
{
int move = BEST_MOVESIdea;
if (isLegal(move, board))
{
cout << move << endl;
return move;
}

}

}

void annouceWinner(char winner, char computer, char human)
{
if (winner == computer)
{
cout << winner << "'s won!\n";
cout << " HA! foolish meatbag you could never beatthe mind of a machine.\n";
cout << " Your fall shall cost you your flesh.\n";
}
else if (winner == human)
{
cout << winner << "'s won!\n";
cout << "....celebrate this will be your last\n";
cout << " for next I shall rain doom.\n";

}
else
{
cout << "it's a tie.\n";
cout << "you have escaped punishment meat bag....this time\n";
cout << "....\n";
}
}


and this is the stuff from the output window:

1>------ Build started: Project: hi2, Configuration: Debug Win32 ------
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>hi2.cpp
1>c:\documents and settings\secret\my documents\visual studio 2005\projects\hi2\hi2\hi2.cpp(172) : warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
1>c:\documents and settings\secret\my documents\visual studio 2005\projects\hi2\hi2\hi2.cpp(176) : warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
1>c:\documents and settings\secret\my documents\visual studio 2005\projects\hi2\hi2\hi2.cpp(186) : warning C4018: '<' : signed/unsigned mismatch
1>c:\documents and settings\secret\my documents\visual studio 2005\projects\hi2\hi2\hi2.cpp(203) : warning C4018: '<' : signed/unsigned mismatch
1>c:\documents and settings\secret\my documents\visual studio 2005\projects\hi2\hi2\hi2.cpp(218) : warning C4018: '<' : signed/unsigned mismatch
1>c:\documents and settings\secret\my documents\visual studio 2005\projects\hi2\hi2\hi2.cpp(229) : warning C4715: 'computerMove' : not all control paths return a value
1>Compiling manifest to resources...
1>Linking...
1>hi2.obj : error LNK2019: unresolved external symbol "void __cdecl announceWinner(char,char,char)" ( announceWinner@@YAXDDD@Z) referenced in function _main
1>hi2.obj : error LNK2019: unresolved external symbol "int __cdecl computerMove(class std::vector<char,class std::allocator<char> > const &,char)" ( computerMove@@YAHABV $vector@DV $allocator@D@std@@@std@@D@Z) referenced in function _main
1>hi2.obj : error LNK2019: unresolved external symbol "char __cdecl opponent(char)" ( opponent@@YADD@Z) referenced in function _main
1>C:\Documents and Settings\secret\My Documents\Visual Studio 2005\Projects\hi2\Debug\hi2.exe : fatal error LNK1120: 3 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\secret\My Documents\Visual Studio 2005\Projects\hi2\hi2\Debug\BuildLog.htm"
1>hi2 - 4 error(s), 6 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



don't know how to turn the smilies off this is my first post but I hope some can help

thank you in advance,
Mike


Answer this question

new to c++ and VC++ express with linker errors

  • KC-Jenner

    announceWinner is misspelled as annouceWinner
    computerMove is implemented using a different prototype from its declaration
    opponent is misspelled as oppenent

     



  • new to c++ and VC++ express with linker errors