title: C++ function returning 'inf' instead of double
body: <p>I have the following simple code that computes the nth harmonic number. No matter what I try I keep getting an 'inf' value in the output. How is this possible, even if all my variables are doubles?</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  double harmonic(double n){
      double h = 0.0;
      while(n &gt;= 0){
          h = h + (1.0/n);
          n = n-1.0;
  
      }
      return(h);
  }
  int main(int argc, char** argv) {
      double n;
      cout &lt;&lt; "enter an integer: ";
      cin &gt;&gt; n;
      cout &lt;&lt; "The " &lt;&lt; n &lt;&lt; "th harmonic number is: ";
      cout &lt;&lt; harmonic(n) &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>