/*
 * Project2.c 
 * Chapter 7
 * By John Stile
 * Purpose: Write a program that reads two intagers xx, yy.
 *          output xx to the power of yy.
 *          Use one or more loops
 *          Use pow()
 */
#include <stdio.h>
#include <math.h>
#define DEBUG 0
////////////////////////////////////////////
int input_number(void) // header for input_number, takes nothing, returns int
{
  float zz; // declare float

  do  // execute bock before evaluating while
  {
    printf("integer: "); // prompt for input

    scanf("%f", &zz); // read float from stdin

    getchar(); // clear input buffer

  } while ( ( (int)zz != zz) && printf("Not and Int.\n Enter an ") ); // keep asking  while zz is not an int
                                                                   // print warning as well

  return ((int)zz); 
}
////////////////////////////////////////////
void print_result( int ll, int mm, int pp )
{
    printf("%d to the %d = %d\n", ll, mm, pp); // print result
}  
////////////////////////////////////////////
int main(void)
{
  int ii,xx,yy; // declare 3 integers 
  float result=1; // declare 1 float  
 
  printf("Input First "); // prompt for input
  xx=input_number();
 
  printf("Input Second: "); // prompt for input
  yy=input_number();
 
  if ( yy == 0 ) // easy calculation
  {
    print_result( xx, yy, 1); // print result
    return 0;
  }
 
  if ( xx == 1 ) // easy calcuation
  {
    print_result(xx, yy, xx); // print result 
  }

  for( ii=1; ii<=yy; ii=ii+1) // run the loop yy times
  {
    if ( DEBUG == 1 )
    {
      printf("xx=%d, ii=%d, result=%f\n", xx,ii,result);
    }
    result=(result*xx) ; // each time through, we multiply xx by the previous result
  } 

  if ( (int)pow(xx,yy) == result )
  {  
    print_result(xx,ii,(int)result); 
  }
  return 0; // return 0 to calling function
}