title: Variables not declared in scope error/too few arguments to function
body: <p>I am writing a simple code to take a number and a power based off user input and square the number to that power using functions. While attempting to compile the code, though, I get multiple errors.  here is the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  double power(double&amp; n1, sq)
  {
      for (int i = 0; i &lt; sq; i++) {
          n1* n1;
      }
      return n1;
  }
  
  int main()
  {
      double power(double&amp;);
      double num1, square;
      cout &lt;&lt; "Enter a number IMMEDIATLY: ";
      cin &gt;&gt; num1;
      cout &lt;&lt; "\nEnter a power: ";
      cin &gt;&gt; square;
      power();
      cout &lt;&lt; num1 &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>Here are the errors that I am receiving: </p>
  
  <pre><code>||=== Build: Debug in practice (compiler: GNU GCC Compiler) ===|
  |5|error: 'sq' has not been declared|
  In function 'double power(double&amp;, int)':|
  |6|error: 'sq' was not declared in this scope|
  |7|warning: statement has no effect [-Wunused-value]|
  In function 'int main()':|
  |22|error: too few arguments to function 'double power(double&amp;)'|
  |15|note: declared here|
  |17|warning: unused variable 'ans' [-Wunused-variable]|
  ||=== Build failed: 3 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|
  </code></pre>
  
  <p>Any help or light shed on how to fix these errors would be much appreciated, for i have been stumped for quite sometime.  Thank you!</p>
  
  <p>edit: so I have parsed square as an int and initialized the variables into the power() (as you guys have said) but now the code produces the incorrect answer as the output (anything bigger than squaring the number produces incorrect output).</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  double power(double&amp; n1, int&amp; sq) {
  for (int i=2; i&lt;=sq; i++) {
          n1*=n1;
  }
  return n1;
  
  }
  
  int main()
  {
  double power(double&amp; n1, int&amp; sq);
  double num1;
  int square;
  cout &lt;&lt; "Enter a number IMMEDIATLY: ";
  cin &gt;&gt; num1;
  cout &lt;&lt; "\nEnter a power: ";
  cin &gt;&gt; square;
   power(num1, square);
  cout &lt;&lt; num1 &lt;&lt; endl;
  return 0;
  }
  </code></pre>