title: Why does the simple arithmetic subtraction not work in the "if" condition?
body: <p>I have 2 arrays with elements in them. I used hashing to get the frequencies of each element which occurs more than one time. <code>mapcheckA</code> contains the frequencies of elements of first array and <code>mapcheckB</code> contains the frequencies of the other array. I am trying to delete/erase any duplicates of elements from both the unordered maps. Here is the code that does it:</p>
  <pre><code>for (auto i : mapcheckA) {
    if (mapcheckB.find(i.first) != mapcheckB.end()) {
      if (i.second &gt;=
          mapcheckB.find(i.first)
              -&gt;second) {  // This block of code doesn't work as expected
        i.second -= mapcheckB.find(i.first)-&gt;second;
        mapcheckB.erase(i.first);
      } else {
        mapcheckB.find(i.first)-&gt;second -= i.second;
        mapcheckA.erase(i.first);
      }
    }
  }
  
  for (auto i1 : mapcheckA) {
    cout &lt;&lt; i1.first &lt;&lt; &quot;\t&quot; &lt;&lt; i1.second &lt;&lt; endl;
  }
  
  for (auto i : mapcheckB) {
    cout &lt;&lt; i.first &lt;&lt; &quot;\t&quot; &lt;&lt; i.second &lt;&lt; endl;
  }
  </code></pre>
  <p>When I enter elements in such a way that first array contains element with more frequency than in the second array, like this:</p>
  <pre><code>arrayA = [ 1, 1, 1, 1, 4, 4 ];  // Here frequency of &quot;1&quot; is 4.
  arrayB = [ 2, 2, 1, 1, 3, 3 ];  // Here frequency of &quot;1&quot; is 2.
  </code></pre>
  <p>In this situation the block of code in the &quot;if&quot; condition does not change the frequency of 1 to 2.
  If I change the order of arrays, then the code works fine. What am I doing wrong here?</p>