ASAP!! My compiler is giving me error message.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • charmeda103
    New Member
    • Oct 2008
    • 36

    ASAP!! My compiler is giving me error message.

    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


    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;
    }
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    All they except linking errors are warning, i do not know what exactly is wrong because i don't want to search all the text for possible occasion of them ( as you didn't provide line numbers for them). They are written in plain English and are easy to fix if you know line numbers. Link error comes from the fact you declared
    void FillUpTheBoard( int pieces, char GamePieces[])
    and implemented
    void FillUpTheBoard( int& pieces, char GamePieces[])

    with & .
    You can't just 4ange valued-passed to reference-passed argument.
    Change int to one without & if you are not changing pieces and not passing changed value back to main program.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      You have two errors:
      1) The function prototype for FillUpThe Board is incorrect. You have:
      Code:
      void FillUpTheBoard(int, char[]);
      when it should be:
      Code:
      void FillUpTheBoard(int&, char[]);
      2) The isillegal function name is misspelled. You have:
      Code:
      isIlegal
      when it should be:
      Code:
      isillegal

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        The following snippet is from lines 140-144.
        Code:
                if(GamePieces[k]=='*') 
                { 
                    GamePieces[k]=='*'; 
                    break; 
                }
        The line before the break compares GamePieces[k] to '*'. If they are equal, then the integer value '1' is discarded; otherwise the integer value '0' is discarded. The compiler warning points out that '==' in this context is meaningless; and goes on to suggest that perhaps you meant '='. In actuality, this line should probably be deleted.

        Comment

        Working...