title: How to calculate to the power of n in c without using pow or anything from the math.h library
body: <p>The task goes like this:</p>
  <p>Write a program that calculates the power of a number (as a pow function from the &quot;math.h&quot; library), except the limitation here is that the exponent can only be an integer. The base and exponent are entered from the keyboard, where the base can be of the real type, while the exponent is a positive or negative integer. Attention should be paid to checking data entry; special treatment should be given to cases where the number is not entered and when the number entered is not an integer when entering the exponent!</p>
  <p>Example input/output:</p>
  <pre class="lang-none prettyprint-override"><code>Enter a base number: abc
  You didn't enter a number!
  
  Enter a base number: 3.3
  Enter exponent: something
  You didn't enter a number!
  
  Enter a base number: 3.3
  Enter exponent: 5
  3.3^5 = 391.354
  
  Enter a base number: 12
  Enter exponent: 2.5
  Entered number is not an integer!
  </code></pre>
  <p>This is my code so far:</p>
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  
  int main() {
  
      double base, result = 1;
      int exp, i;
      
      printf(&quot;Enter a base number: &quot;);
      scanf(&quot;%lf&quot;, &amp;base);
  
      printf(&quot;Enter exponent: &quot;);
      scanf(&quot;%d&quot;, &amp;exp);
  
      for (i=1; i&lt;=exp; i++) {
          result *= base;
      }
      printf(&quot;%.2lf^%d = %.2lf&quot;, base,exp,result);
  
      return 0;
  }
  </code></pre>
  <p>It calculates the power of n successfully. But how do I add the &quot;You didn't enter a number!&quot; text when the input is wrong. Also, some results should be printed with 3 decimals, some with 6, etc.(depends on the result).</p>