Start New Discussion within our Software Development Community

ok...i'm having trouble changing a value in a array into a character

void gameon(int **game,int &size,int &x,int &y,int &score1,int &score2)
   int i,j,num1,num2;
   cout<<"Please enter a number from the selected row/column -->";
          cout<<"Number found"<<endl;

i can't seem to change that specific number into 'X'..
can u guys help me out...

Two problems in one statement.


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.

This article has been dead for over six months. Start a new discussion instead.