 <p>Try this:</p> <pre><code> for (int x=0;x&lt;4;x++) flag[x]=guess[x]==answer[x]?1:0; for (int slot = 0;slot &lt; 4;slot++) { if (guess[slot] == answer[slot]) black++; else for (int s=0;s &lt; 4;s++) if (!flag[s] &amp;&amp; guess[slot] == answer[s]) { white++; flag[s]=1; break; } } </code></pre>