By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,503 Members | 1,628 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,503 IT Pros & Developers. It's quick & easy.

ASAP!! My compiler is giving me error message.

P: 36
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)" (?FillUpTheBoard@@YAXHQAD@Z) referenced in function _main
5. error LNK2019: unresolved external symbol "int __cdecl isillegal(char * const,int,int,int)" (?isillegal@@YAHQADHHH@Z) referenced in function "void __cdecl UserPlayerTurn(char * const,int &,int)" (?UserPlayerTurn@@YAXQADAAHH@Z)
6: fatal error LNK1120: 2 unresolved externals


Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <iomanip>
  5. #include <cmath>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. void SetPrompts(int&, bool&);
  11. void FillUpTheBoard(int, char[]);
  12. void PrintedBoard(char[], int);
  13. void ComputerPlayerTurn(char[], int&, int);
  14. void UserPlayerTurn(char[], int&, int);
  15. int isillegal(char[], int, int, int);
  16. void TheMove(char [], int, int, int);
  17. int theLastTurn(char [], int);
  18.  
  19.  
  20.  
  21. int main()
  22. {
  23.     int pieces, size, piecesSelection=0, score_OfUser=0, score_ComputerPlayer=0;
  24.     char GamePieces[20];
  25.     bool COMPUTER_TURN, COMPUTER_FIRST, toPlayAgain;
  26.     do
  27.     {
  28.  
  29.  
  30.         SetPrompts(pieces, COMPUTER_FIRST);
  31.         COMPUTER_TURN=COMPUTER_FIRST;
  32.         FillUpTheBoard(pieces, GamePieces);
  33.         //PrintedBoard(GamePieces, pieces);
  34.  
  35.  
  36.  
  37.         do
  38.         {
  39.             if(COMPUTER_TURN==true)
  40.             {
  41.                 ComputerPlayerTurn(GamePieces,piecesSelection,pieces);
  42.                 PrintedBoard(GamePieces,pieces);
  43.                 COMPUTER_TURN=false;
  44.             }
  45.             else
  46.             {
  47.                 UserPlayerTurn(GamePieces,piecesSelection, pieces);
  48.                 PrintedBoard(GamePieces, pieces);
  49.                 COMPUTER_TURN=true;
  50.             }
  51.         }while(!theLastTurn(GamePieces, pieces));
  52.         if(COMPUTER_TURN)
  53.         {
  54.             score_OfUser++;
  55.             cout<< "Congratulations, You Won The Game Hoorray for You!" << endl;
  56.         }
  57.         else
  58.         {
  59.             score_ComputerPlayer++;
  60.             cout <<"Opps!, you made the last turn sorry you lost the Game!" <<endl;
  61.         }
  62.         cout << "The Score now is:" << score_OfUser << ":Computer Player" << score_ComputerPlayer<<endl;
  63.         cout << "Would Like to Play again?" << endl;
  64.         char userAnswer;
  65.         cin >> userAnswer;
  66.         if(userAnswer=='y'||userAnswer=='Y')
  67.         {
  68.             cout << "Lets Start Over!" << endl;
  69.             toPlayAgain=true;
  70.         }
  71.         else
  72.         {
  73.             toPlayAgain=false;
  74.             cout << "Thank You for Playing Circular Nim. Please come again!" << endl;
  75.         }
  76.     }while(toPlayAgain==true);
  77.  
  78.  
  79.  
  80.     return 0;
  81. }
  82.  
  83. void SetPrompts(int& pieces, bool& COMPUTER_TURN)
  84. {
  85.  
  86.     char userAnswer;
  87.     cout << "Welcome to the game Circular Nim!" << endl << endl;
  88.  
  89.     do
  90.     {
  91.         cout << "How Many Pieces Would You Like to Start with?" << endl;
  92.         cin >> pieces;
  93.         if(pieces<5||20<pieces)
  94.             cout << "You can only choose a number between 5 and 20. Please Try Again." << endl << endl;
  95.     }while(pieces<5||20<pieces);    
  96.  
  97.      cout << "Would you like to go first?(Y/N)";
  98.      cin >> userAnswer;
  99.     if(userAnswer=='y'||userAnswer=='Y')
  100.     {
  101.         cout << "OK, You can Start the Game." << endl;
  102.         COMPUTER_TURN=false;
  103.     }
  104.     else
  105.     {
  106.         COMPUTER_TURN=true;
  107.         cout << "OK, I will Start the Game First." << endl;
  108.     }
  109.  
  110.  
  111. }
  112.  
  113. void FillUpTheBoard(int& pieces, char GamePieces[])
  114. {
  115.     for(int k=0; k<pieces; k++)
  116.     {
  117.         GamePieces[k]='*';
  118.     }
  119. }
  120. void PrintedBoard(char GamePieces[], int pieces)
  121. {
  122.     cout << endl << endl << "This is What the Current Board Looks Like" << endl << endl;
  123.     for (int k=0; k<pieces; k++)
  124.     {
  125.         cout << left << setw(3)<<k;
  126.         cout << endl;
  127.     }
  128.     for(int k=0; k<pieces; k++)
  129.     {
  130.  
  131.         cout << setw(2)<< GamePieces[k]<< ' ';
  132.         cout << endl;
  133.     }
  134. }
  135. void ComputerPlayerTurn(char GamePieces[], int& piecesChoice, int pieces)
  136. {
  137.     cout << endl << endl << "Ok Now its My Turn!"<<endl;
  138.     for(int k=0; k<pieces; k++)
  139.     {
  140.         if(GamePieces[k]=='*')
  141.         {
  142.             GamePieces[k]=='*';
  143.             break;
  144.         }
  145.     }
  146.  
  147. }
  148. void UserPlayerTurn(char GamePieces[], int& piecesSelection, int size)
  149. {
  150.     char userAnswer;
  151.     int count;
  152.     int illegal;
  153.  
  154.     do
  155.     {
  156.         cout << "Now Its Your turn! How Many Pieces would you like?";
  157.         cin>> count;
  158.         while(count>3)
  159.         {
  160.             cout <<"This amount of pieces is illegal.\n";
  161.             cout << "Please enter a different integer \n";
  162.             cin >> count;
  163.         }
  164.         cout << "Enter the first piece to take \n";
  165.         cin >> piecesSelection;
  166.         illegal=isillegal(GamePieces,size, count, piecesSelection);
  167.         if(illegal)
  168.         {
  169.             cout<<"This is an illegal move \n";
  170.             cout<< "Start Over! \n";
  171.         }
  172.     }while(illegal);
  173.         TheMove(GamePieces, size, count, piecesSelection);
  174.  
  175. }
  176. int isIlegal(char GamePieces[], int size, int count, int firstPiece)
  177. {
  178.     int illegal=0;
  179.     if(firstPiece>0)
  180.     {
  181.         for(int k=0; k<count; k++)
  182.         {
  183.             int checkPiece=(k+firstPiece)%size;
  184.             if(checkPiece==0) checkPiece=size;
  185.             if(GamePieces[checkPiece-1]=='_')
  186.             {
  187.                 illegal=1;
  188.                 break;
  189.             }
  190.         }
  191.     }
  192.     else
  193.     {
  194.         illegal=1;
  195.     }
  196.     return illegal;
  197. }
  198. void TheMove(char GamePieces[], int size, int count, int firstPiece)
  199. {
  200.     for(int k=0; k<count; k++)
  201.     {
  202.         int thePieceToChoose=(k+firstPiece)%size;
  203.         if(thePieceToChoose==0)thePieceToChoose=size;
  204.         GamePieces[thePieceToChoose-1]='_';
  205.     }
  206.  
  207.  
  208. }
  209. int theLastTurn(char GamePieces[], int pieces)
  210. {
  211.     int last=1;
  212.     for(int k=0; k<pieces; k++)
  213.     {
  214.         if(GamePieces[k]=='*')
  215.         {
  216.             last=0;
  217.             break;
  218.         }
  219.     }
  220.     return last;
  221. }
  222.  
  223.  
Nov 17 '08 #1
Share this Question
Share on Google+
3 Replies


100+
P: 687
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.
Nov 18 '08 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
You have two errors:
1) The function prototype for FillUpThe Board is incorrect. You have:
Expand|Select|Wrap|Line Numbers
  1. void FillUpTheBoard(int, char[]); 
  2.  
when it should be:
Expand|Select|Wrap|Line Numbers
  1. void FillUpTheBoard(int&, char[]); 
  2.  
2) The isillegal function name is misspelled. You have:
Expand|Select|Wrap|Line Numbers
  1. isIlegal
  2.  
when it should be:
Expand|Select|Wrap|Line Numbers
  1. isillegal
  2.  
Nov 18 '08 #3

Expert 100+
P: 2,415
The following snippet is from lines 140-144.
Expand|Select|Wrap|Line Numbers
  1.         if(GamePieces[k]=='*') 
  2.         { 
  3.             GamePieces[k]=='*'; 
  4.             break; 
  5.         } 
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.
Nov 18 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.