title: I am trying to make a custom pow() function but my for loops are not working - C
body: <p>I am trying to make a custom pow() function to compare the results of an actual pow function, but it is not working. When the base is 1 it works fine but after that MyPower function will return 1 for anything to the first power, so it will say. </p>
  
  <p>Testing 1.000000 to the 1 power<br>
  Testing 1.000000 to the 2 power<br>
  Testing 1.000000 to the 3 power<br>
  Testing 1.000000 to the 4 power<br>
  2.000000 to the 1 is 2.000000, result is 1.000000<br>
  2.000000 to the 2 is 4.000000, result is 2.000000<br>
  2.000000 to the 3 is 8.000000, result is 4.000000<br>
  2.000000 to the 4 is 16.000000, result is 8.000000     </p>
  
  <p>and it will go on to be on one exponent value less for all the rest of the bases. I believe the error is occurring in the MyPower() function but I am not sure.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  
  double base, x;
  int exponent, i, z;
  
  double MyPower(double base, int exponent);
  void DoTest(double base, int exponent);
  
  
  double MyPower(double base, int exponent){
      double x = 1;
      for(z = 1; z &lt; exponent; z++){
          x *= base;
      }
      return x;
  }
  
  int main(void){
      int i, j;
      for(i = 1; i &lt; 5; i++){
          for(j = 1; j &lt; 5; j++){
              DoTest(i,j);
          }
      }
  }
  
  
  void DoTest(double base, int exponent){
      double test1 = MyPower(base, exponent);
      double pow_result = pow(base, exponent);
      if(test1 == pow_result){
          printf("Testing %f to the %d power\n", base, exponent);
      }
      else{
          printf("%f to the %d is %f, result is %f\n", base, exponent, pow_result, test1);
      }
  }
  </code></pre>