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

Please How do I fix my program i keep getting errors!

P: 36
here are the error messages how do i fix it. i am creating the game called Circular Nim!
my program also keeps repeating why. anything would help!

1.error C2234: 'GamePieces' : arrays of references are illegal
2.error C2440: '=' : cannot convert from 'char' to 'char *'
3. error C2234: 'GamePieces' : arrays of references are illegal
4.error C2137: empty character constant



Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. #include <cmath>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. void SetPrompts(int&, bool&);
  10. void FillUpTheBoard(int&, char[]);
  11. void PrintedBoard(char[], int&);
  12. void ComputerTurn(char[], int&, int&);
  13.  
  14.  
  15. int main()
  16. {
  17.     int pieces, size, piecesSelection=0;
  18.     char GamePieces[20];
  19.     bool COMPUTER_TURN=false;
  20.  
  21.     SetPrompts(pieces, COMPUTER_TURN);
  22.     size=pieces-1;
  23.     FillUpTheBoard(pieces, GamePieces);
  24.     PrintedBoard(GamePieces, pieces);
  25.  
  26.     do
  27.     {
  28.         if(COMPUTER_TURN==true)
  29.         {
  30.             ComputerTurn(GamePieces,piecesSelection,pieces);
  31.             PrintedBoard(GamePieces,pieces);
  32.             COMPUTER_TURN=false;
  33.         }
  34.         else
  35.         {
  36.  
  37.             PrintedBoard(GamePieces, pieces);
  38.             COMPUTER_TURN=true;
  39.         }
  40.     }while(GamePieces[0]!='_');
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.     return 0;
  56. }
  57.  
  58. void SetPrompts(int& pieces, bool& COMPUTER_TURN)
  59. {
  60.  
  61.     char userAnswer;
  62.     cout << "Welcome to the game Circular Nim!" << endl << endl;
  63.  
  64.     do
  65.     {
  66.         cout << "How Many Pieces Would You Like to Start with?" << endl;
  67.         cin >> pieces;
  68.         if(pieces<5||20<pieces)
  69.             cout << "You can only choose a number between 5 and 20. Please Try Again." << endl << endl;
  70.     }while(pieces<5||20<pieces);    
  71.  
  72.      cout << "Would you like to go first?(Y/N)";
  73.      cin >> userAnswer;
  74.     if(userAnswer=='y'||userAnswer=='Y')
  75.     {
  76.         cout << "OK, You can Start the Game." << endl;
  77.         COMPUTER_TURN=false;
  78.     }
  79.     else
  80.     {
  81.         COMPUTER_TURN=true;
  82.         cout << "OK, I will Start the Game First." << endl;
  83.     }
  84.  
  85.  
  86. }
  87.  
  88. void FillUpTheBoard(int& pieces, char& GamePieces[])
  89. {
  90.     for(int k=0; k<pieces; k++)
  91.     {
  92.         GamePieces[k]='*';
  93.     }
  94. }
  95. void PrintedBoard(char& GamePieces[], int& pieces)
  96. {
  97.     cout << endl << endl << "This is What the Current Board Looks Like" << endl << endl;
  98.     for (int k=0; k<pieces; k++)
  99.     {
  100.         cout << left << setw(3)<<k;
  101.         cout << endl;
  102.  
  103.         cout << setw(2) << GamePieces[k]<<'';
  104.         cout << endl;
  105.     }
  106. }
  107. void ComputerTurn(char GamePieces[], int& piecesChoice, int& pieces)
  108. {
  109.     int computerMove=piecesChoice+1;
  110.     cout << endl << endl << "OK, Now Its My Turn to Play!" << endl;
  111.     if(computerMove<=pieces&&GamePieces[computerMove]!='_')
  112.         GamePieces[computerMove]='_';
  113. }
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
Nov 15 '08 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
Expand|Select|Wrap|Line Numbers
  1. void FillUpTheBoard(int& pieces, char& GamePieces[]) 
  2. etc...
  3. void PrintedBoard(char& GamePieces[], int& pieces) 
  4. etc...
  5.  
You cannot have an array of references. This argument should be an array of char.

Remember, when you pass an array ot a function all you pass is the address of element 0. In this case the address of a char.

Fix these errors and most of the opthers will go away.

The one about an empty character literal means that when you use ' ' for a character literal, you need to put a character in there.
Nov 16 '08 #2

Post your reply

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