title: How to fix implicit conversion warnings?
body: <p>I'm reading C++ How To Program 9th Edition, trying to learn c++, and attempting the exercise with the Knight's Problem in Chapter 7.</p>
  
  <p>Based on the "64" in the output, the code clearly has some sort of logic error (which I will fix on my own), but before doing this, I'm stuck on understanding and what to do about the compiler warnings.</p>
  
  <p>I've declared board as a two-dimensional array of unsigned int because it can only contain values 0-7. Likewise, I've declared variables in for loops as unsigned int, for the same reason.</p>
  
  <p>I've read responses on stackoverflow about this but they quickly go over my head.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;array&gt;
  #include &lt;iomanip&gt;
  
  using namespace std;
  
  void printArray(const array&lt; array&lt; unsigned int, 8 &gt;, 8 &gt;);
  
  int main() {
    array&lt; array&lt; unsigned int, 8 &gt;, 8 &gt; board = {};
    array&lt; int, 8 &gt; horizontal = {{ 2, 1, -1, -2, -2, -1, 1, 2 }};
    array&lt; int, 8 &gt; vertical = {{ -1, -2, -2, -1, 1, 2, 2, 1 }};
    unsigned int currentRow = 0;
    unsigned int currentCol = 0;
    for (unsigned int i = 0; i &lt; 64; i++) {
      board[currentRow][currentCol] = i + 1;
      for (unsigned int j = 0; j &lt; 8; j++) {
        if (currentRow + horizontal[j] &gt;= 0 &amp;&amp;
          currentRow + horizontal[j] &lt; 8 &amp;&amp;
          currentCol + vertical[j] &gt;= 0 &amp;&amp;
          currentCol + vertical[j] &lt; 8 &amp;&amp;
          board[currentRow + horizontal[j]][currentCol + vertical[j]] == 0
        ) {
          currentRow = currentRow + horizontal[j];
          currentCol = currentCol + vertical[j];
          break;
        }
      }
    }
    printArray(board);
  }
  
  void printArray(const array&lt; array&lt; unsigned int, 8 &gt;, 8 &gt; myBoard) {
    for ( unsigned int i = 0; i &lt; 8; i++) {
      for ( unsigned int j = 0; j &lt; 8; j++) {
        cout &lt;&lt; '[' &lt;&lt; setw(2) &lt;&lt; setfill('0') &lt;&lt; myBoard[i][j] &lt;&lt; "] ";
      }
      cout &lt;&lt; endl;
    }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>~/Programming/cpp/knight =&gt; make
  rm -fr build/*
  clang++ -std=c++11 -stdlib=libc++ -Weverything -Wno-c++98-compat src/main.cpp -o build/main -Isrc/
  src/main.cpp:18:24: warning: implicit conversion changes signedness: 'value_type' (aka 'int') to 'unsigned int' [-Wsign-conversion]
        if (currentRow + horizontal[j] &gt;= 0 &amp;&amp;
                       ~ ^~~~~~~~~~~~~
  src/main.cpp:18:38: warning: comparison of unsigned expression &gt;= 0 is always true [-Wtautological-compare]
        if (currentRow + horizontal[j] &gt;= 0 &amp;&amp;
            ~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~
  src/main.cpp:19:22: warning: implicit conversion changes signedness: 'value_type' (aka 'int') to 'unsigned int' [-Wsign-conversion]
          currentRow + horizontal[j] &lt; 8 &amp;&amp;
                     ~ ^~~~~~~~~~~~~
  src/main.cpp:20:22: warning: implicit conversion changes signedness: 'value_type' (aka 'int') to 'unsigned int' [-Wsign-conversion]
          currentCol + vertical[j] &gt;= 0 &amp;&amp;
                     ~ ^~~~~~~~~~~
  src/main.cpp:20:34: warning: comparison of unsigned expression &gt;= 0 is always true [-Wtautological-compare]
          currentCol + vertical[j] &gt;= 0 &amp;&amp;
          ~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~
  src/main.cpp:21:22: warning: implicit conversion changes signedness: 'value_type' (aka 'int') to 'unsigned int' [-Wsign-conversion]
          currentCol + vertical[j] &lt; 8 &amp;&amp;
                     ~ ^~~~~~~~~~~
  src/main.cpp:22:28: warning: implicit conversion changes signedness: 'value_type' (aka 'int') to 'unsigned int' [-Wsign-conversion]
          board[currentRow + horizontal[j]][currentCol + vertical[j]] == 0
                           ~ ^~~~~~~~~~~~~
  src/main.cpp:22:56: warning: implicit conversion changes signedness: 'value_type' (aka 'int') to 'unsigned int' [-Wsign-conversion]
          board[currentRow + horizontal[j]][currentCol + vertical[j]] == 0
                                                       ~ ^~~~~~~~~~~
  src/main.cpp:24:35: warning: implicit conversion changes signedness: 'value_type' (aka 'int') to 'unsigned int' [-Wsign-conversion]
          currentRow = currentRow + horizontal[j];
                                  ~ ^~~~~~~~~~~~~
  src/main.cpp:25:35: warning: implicit conversion changes signedness: 'value_type' (aka 'int') to 'unsigned int' [-Wsign-conversion]
          currentCol = currentCol + vertical[j];
                                  ~ ^~~~~~~~~~~
  10 warnings generated.
  ./build/main
  [01] [24] [09] [00] [00] [26] [37] [00]
  [10] [41] [02] [25] [36] [00] [00] [27]
  [23] [08] [11] [40] [21] [38] [00] [00]
  [64] [03] [22] [35] [00] [00] [28] [00]
  [07] [12] [05] [20] [39] [34] [00] [00]
  [04] [17] [14] [31] [00] [29] [00] [00]
  [13] [06] [19] [16] [33] [00] [00] [00]
  [18] [15] [32] [00] [30] [00] [00] [00]
  </code></pre>