title: Calculate power with a recursive function on C++
body: <p>I need to make a program that calculates the power of a given number using a recursive function. I wrote this I can't get it to work, once I get to the function itself it breaks. Any help? Thanks.</p>
  
  <pre><code>#include"stdafx.h"
  #include&lt;stdio.h&gt;
  #include&lt;iostream&gt;
  
  using namespace std;
  
  float power(float a, unsigned int b);
  
  int main()
  {
  
      float a = 0;
      unsigned int b = 0;
  
      cout &lt;&lt; "Insert base - ";
  
      cin &gt;&gt; a;
  
      cout &lt;&lt; "Insert index - ";
  
      cin &gt;&gt; b;
  
      float result;
  
      result = power(a, b);
  
      cout &lt;&lt; result;
  
      return 0;
  }
  
  float power(float a, unsigned int b)
  {
  
      if (b &lt;= 0)
      {
          return a; 
      }
  
      return (a*power(a, b--));
  }
  </code></pre>