943,667 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 498
  • C++ RSS
Sep 5th, 2009
0

changing array value...

Expand Post »
ok...i'm having trouble changing a value in a array into a character
C++ Syntax (Toggle Plain Text)
  1. void gameon(int **game,int &size,int &x,int &y,int &score1,int &score2)
  2. {
  3. int i,j,num1,num2;
  4. cout<<"Please enter a number from the selected row/column -->";
  5. cin>>num1;
  6. for(j=0;j<size;j++)
  7. {
  8. if(num1==game[x][j])
  9. {
  10. cout<<"Number found"<<endl;
  11. game[x][j]=='X';
  12. score1=score1+num1;
  13. y=j;
  14. }
  15. }
  16. display(game,size,score1,score2);
  17. }

i can't seem to change that specific number into 'X'..
can u guys help me out...
Reputation Points: 10
Solved Threads: 0
Light Poster
gopi17 is offline Offline
39 posts
since Sep 2008
Sep 5th, 2009
0

Re: changing array value...

Two problems in one statement.
C++ Syntax (Toggle Plain Text)
  1. game[x][j]=='X';

First, you're using the equality test ( == ) instead of assignment ( = ).
Second, you're trying to assign a character to an integer variable. This will work (when you fix problem 1) but will not give you the result I think you're expecting. What will be assigned to the array element is the ASCII value of 'X' (which is 88, if I read my ASCII chart right.)

If you want to mark the spot as used or free or whatever, you'll need to pick a value out of the range of allowable values. For instance, if the valid data can be any positive number greater than 0 (zero), use 0. If 0 could be a valid data item, how about some negative number? If all possible numbers are potentially valid, then you need some other way to indicate the cell is empty/available or whatever. Perhaps a parallel array where you simply mark 0 or 1 to indicate that the corresponding cell in the data array is available or not.
Reputation Points: 1268
Solved Threads: 228
Posting Virtuoso
vmanes is offline Offline
1,895 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: linking error
Next Thread in C++ Forum Timeline: Help looping a program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC