title: Simple C++ Error: "... undeclared (first use this function)"
body: <p>I am working on my first C++ program for school. For some reason I am getting the following error when I try to compile it:</p>
  <pre><code>`truncate' undeclared (first use this function)
  </code></pre>
  <p>Full Source:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;math.h&gt;
  
  using namespace std;
  
  #define CENTIMETERS_IN_INCH 2.54
  #define POUNDS_IN_KILOGRAM 2.2
  
  int main() {
      double feet, inches, centimeters, weight_in_kg, weight_in_lbs;
  
      // get height in feet and inches
      cout &lt;&lt; &quot;Enter height (feet): &quot;;
      cin &gt;&gt; feet;
      cout &lt;&lt; &quot;Enter (inches): &quot;;
      cin &gt;&gt; inches;
  
      // convert feet and inches into centimeters
      centimeters = ((12 * feet) + inches) * CENTIMETERS_IN_INCH;
  
      // round 2 decimal places and truncate
      centimeters = truncate(centimeters);
  
      printf(&quot;Someone that is %g' %g\&quot; would be %g cm tall&quot;, feet, inches, centimeters);
  
      // weights for bmi of 18.5
      weight_in_kg = truncate(18.5 * centimeters);
      weight_in_lbs = round(weight_in_kg * POUNDS_IN_KILOGRAM);
  
      printf(&quot;18.5 BMI would correspond to about %g kg or %g lbs&quot;, weight_in_kg,   weight_in_lbs);
  
      // weights for bmi of 25
      weight_in_kg = truncate(25 * centimeters);
      weight_in_lbs = round(weight_in_kg * POUNDS_IN_KILOGRAM);
  
      printf(&quot;25.0 BMI would correspond to about %g kg or %g lbs&quot;, weight_in_kg, weight_in_lbs);
  
      // pause output
      cin &gt;&gt; feet;
  
      return 0;
  }
  
  // round result
  double round(double d) {
     return floor(d + 0.5);
  }
  
  // round and truncate to 1 decimal place
  double truncate(double d) {
     return round(double * 10) / 10;
  }
  </code></pre>
  <p>Any help would be appreciated. Thanks.</p>