i trying count how many times specific character appears in 2d array. problem is counting characters in array instead. i'm not sure why.
int p = 0; int p = 0; int r = 0; int r = 0; int n = 0; int n = 0; int b = 0; int b = 0; int q = 0; int q = 0; (int x = 0; x < board_size + 1; x++) // side 9 { (int y = 0; y < board_size; y++) // side 8 { char temp = ' '; // tried using temp pass through, no difference temp = chessboards[x][y]; // cout << temp; // when on prints each element of array list in order number beside if (temp = 'p') // 1 character trying count { ++p; // increments every character it's not checked } } } cout << p << endl << endl; // using test output
it's typo..
if (temp = 'p')
you using assignment operator instead of comparison.
Comments
Post a Comment