I keep getting errors and i looked relooked I cant seem to see what wrong.
from my code can see u where the errors are coming from.
here are the error messages:
1.warning C4101: 'size' : unreferenced local variable
2. warning C4553: '==' : operator has no effect; did you intend '='?
3. warning C4101: 'userAnswer' : unreferenced local variable
4.error LNK2019: unresolved external symbol "void __cdecl FillUpTheBoard( int,char * const)" (?FillUpTheBoar d@@YAXHQAD@Z) referenced in function _main
5. error LNK2019: unresolved external symbol "int __cdecl isillegal(char * const,int,int,i nt)" (?isillegal@@YA HQADHHH@Z) referenced in function "void __cdecl UserPlayerTurn( char * const,int &,int)" (?UserPlayerTur n@@YAXQADAAHH@Z )
6: fatal error LNK1120: 2 unresolved externals
from my code can see u where the errors are coming from.
here are the error messages:
1.warning C4101: 'size' : unreferenced local variable
2. warning C4553: '==' : operator has no effect; did you intend '='?
3. warning C4101: 'userAnswer' : unreferenced local variable
4.error LNK2019: unresolved external symbol "void __cdecl FillUpTheBoard( int,char * const)" (?FillUpTheBoar d@@YAXHQAD@Z) referenced in function _main
5. error LNK2019: unresolved external symbol "int __cdecl isillegal(char * const,int,int,i nt)" (?isillegal@@YA HQADHHH@Z) referenced in function "void __cdecl UserPlayerTurn( char * const,int &,int)" (?UserPlayerTur n@@YAXQADAAHH@Z )
6: fatal error LNK1120: 2 unresolved externals
Code:
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
void SetPrompts(int&, bool&);
void FillUpTheBoard(int, char[]);
void PrintedBoard(char[], int);
void ComputerPlayerTurn(char[], int&, int);
void UserPlayerTurn(char[], int&, int);
int isillegal(char[], int, int, int);
void TheMove(char [], int, int, int);
int theLastTurn(char [], int);
int main()
{
int pieces, size, piecesSelection=0, score_OfUser=0, score_ComputerPlayer=0;
char GamePieces[20];
bool COMPUTER_TURN, COMPUTER_FIRST, toPlayAgain;
do
{
SetPrompts(pieces, COMPUTER_FIRST);
COMPUTER_TURN=COMPUTER_FIRST;
FillUpTheBoard(pieces, GamePieces);
//PrintedBoard(GamePieces, pieces);
do
{
if(COMPUTER_TURN==true)
{
ComputerPlayerTurn(GamePieces,piecesSelection,pieces);
PrintedBoard(GamePieces,pieces);
COMPUTER_TURN=false;
}
else
{
UserPlayerTurn(GamePieces,piecesSelection, pieces);
PrintedBoard(GamePieces, pieces);
COMPUTER_TURN=true;
}
}while(!theLastTurn(GamePieces, pieces));
if(COMPUTER_TURN)
{
score_OfUser++;
cout<< "Congratulations, You Won The Game Hoorray for You!" << endl;
}
else
{
score_ComputerPlayer++;
cout <<"Opps!, you made the last turn sorry you lost the Game!" <<endl;
}
cout << "The Score now is:" << score_OfUser << ":Computer Player" << score_ComputerPlayer<<endl;
cout << "Would Like to Play again?" << endl;
char userAnswer;
cin >> userAnswer;
if(userAnswer=='y'||userAnswer=='Y')
{
cout << "Lets Start Over!" << endl;
toPlayAgain=true;
}
else
{
toPlayAgain=false;
cout << "Thank You for Playing Circular Nim. Please come again!" << endl;
}
}while(toPlayAgain==true);
return 0;
}
void SetPrompts(int& pieces, bool& COMPUTER_TURN)
{
char userAnswer;
cout << "Welcome to the game Circular Nim!" << endl << endl;
do
{
cout << "How Many Pieces Would You Like to Start with?" << endl;
cin >> pieces;
if(pieces<5||20<pieces)
cout << "You can only choose a number between 5 and 20. Please Try Again." << endl << endl;
}while(pieces<5||20<pieces);
cout << "Would you like to go first?(Y/N)";
cin >> userAnswer;
if(userAnswer=='y'||userAnswer=='Y')
{
cout << "OK, You can Start the Game." << endl;
COMPUTER_TURN=false;
}
else
{
COMPUTER_TURN=true;
cout << "OK, I will Start the Game First." << endl;
}
}
void FillUpTheBoard(int& pieces, char GamePieces[])
{
for(int k=0; k<pieces; k++)
{
GamePieces[k]='*';
}
}
void PrintedBoard(char GamePieces[], int pieces)
{
cout << endl << endl << "This is What the Current Board Looks Like" << endl << endl;
for (int k=0; k<pieces; k++)
{
cout << left << setw(3)<<k;
cout << endl;
}
for(int k=0; k<pieces; k++)
{
cout << setw(2)<< GamePieces[k]<< ' ';
cout << endl;
}
}
void ComputerPlayerTurn(char GamePieces[], int& piecesChoice, int pieces)
{
cout << endl << endl << "Ok Now its My Turn!"<<endl;
for(int k=0; k<pieces; k++)
{
if(GamePieces[k]=='*')
{
GamePieces[k]=='*';
break;
}
}
}
void UserPlayerTurn(char GamePieces[], int& piecesSelection, int size)
{
char userAnswer;
int count;
int illegal;
do
{
cout << "Now Its Your turn! How Many Pieces would you like?";
cin>> count;
while(count>3)
{
cout <<"This amount of pieces is illegal.\n";
cout << "Please enter a different integer \n";
cin >> count;
}
cout << "Enter the first piece to take \n";
cin >> piecesSelection;
illegal=isillegal(GamePieces,size, count, piecesSelection);
if(illegal)
{
cout<<"This is an illegal move \n";
cout<< "Start Over! \n";
}
}while(illegal);
TheMove(GamePieces, size, count, piecesSelection);
}
int isIlegal(char GamePieces[], int size, int count, int firstPiece)
{
int illegal=0;
if(firstPiece>0)
{
for(int k=0; k<count; k++)
{
int checkPiece=(k+firstPiece)%size;
if(checkPiece==0) checkPiece=size;
if(GamePieces[checkPiece-1]=='_')
{
illegal=1;
break;
}
}
}
else
{
illegal=1;
}
return illegal;
}
void TheMove(char GamePieces[], int size, int count, int firstPiece)
{
for(int k=0; k<count; k++)
{
int thePieceToChoose=(k+firstPiece)%size;
if(thePieceToChoose==0)thePieceToChoose=size;
GamePieces[thePieceToChoose-1]='_';
}
}
int theLastTurn(char GamePieces[], int pieces)
{
int last=1;
for(int k=0; k<pieces; k++)
{
if(GamePieces[k]=='*')
{
last=0;
break;
}
}
return last;
}
Comment