title: Dividing 2 floating point numbers in C++ produces different results depending on the method used
body: <p>In C++, why does dividing 2 floating point numbers via 2 different mechanisms (inline and via a function call) output different results as per below?</p>
  
  <p>After the following computations where 5 is divided into 4, f1 = 0 and f2 = 0.8.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main() {
      float f1 = 4 / 5;
      float f2 = FloatDivision(4, 5);
      cout &lt;&lt; "f1 equals " &lt;&lt; f1 &lt;&lt; endl;
      cout &lt;&lt; "f2 equals " &lt;&lt; f2 &lt;&lt; endl;
      cin.ignore();
  }
  
  float FloatDivision(float f1, float f2) {
      if (f2 != 0) {
          return f1 / f2;
      } else {
          cout &lt;&lt; "Error: The denominator cannot be zero" &lt;&lt; endl;
          return 0;
      }
  }
  </code></pre>