changing array value...

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 23
Reputation: gopi17 is an unknown quantity at this point 
Solved Threads: 0
gopi17 gopi17 is offline Offline
Newbie Poster

changing array value...

 
0
  #1
Sep 5th, 2009
ok...i'm having trouble changing a value in a array into a character
  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...
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,679
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: changing array value...

 
0
  #2
Sep 5th, 2009
Two problems in one statement.
  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.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC