SOURCE FILE: 030_powCalcA_1.5.cpp



/* 
     Here we add some of the function definitions to the 
     level 1.0 program, so that the loop control starts
     working properly. 
*/

#include <iostream> 
using namespace std ; 

/*  PROTOTYPES */
void  PrintInfo() ;
int   GetInt() ;
bool  GoodInput(int first, int second) ;
int   MyPow(int base, int exponent) ;
void  WriteAnswer (int base, int exp, int ans) ;


/*  ************** */
/*  FUNCTION: MAIN */
/*  ************** */
int main (void) 
{
  int n, m, answer ;

  /* Print info on what the program does */
  PrintInfo() ;
  do
  {
       /* get the two inputs (n and m) */
     n = GetInt() ;
     m = GetInt() ;
       /* if n and m are both positive  */
     if ( GoodInput(n,m) )
     {
         /* compute n to the power m */
       answer = MyPow (n,m) ;
        /* write the answer on the screen */
       WriteAnswer (n,m,answer) ;
     }
  } while (GoodInput(n,m)) ;  /* while n and m are both positive */
  return 0; 
}

/*  FUNCTION: PRINT INFO */
void  PrintInfo() 
{    /* Stub Code */
   cout << "PrintInfo executes.\n" ;
}

/*  FUNCTION: GET INT */
int   GetInt() 
{    
   int entry ;
   cout << "Please enter an integer (<=0 to stop): " ;
   cin >> entry ;
   return entry ;
}

/*  FUNCTION: GOOD INPUT */
bool GoodInput(int first, int second)
{
   return ( (first > 0) && (second > 0) ) ; 
}

/*  FUNCTION: MY POW */
int   MyPow(int base, int exponent) 
{    /* Stub Code */
   cout << "MyPow executes.\n" ;
   cout << "   Parameter base is: " << base << endl ;
   cout << "   Parameter exponent is: " << exponent << endl ;
   return 42 ;
}

/*  FUNCTION: WRITE ANSWER */
void  WriteAnswer (int base, int exp, int ans) 
{    /* Stub Code */
   cout << "WriteAnswer executes.\n" ;
   cout << "   Parameter base is: " << base << endl ;
   cout << "   Parameter exp is: " << exp << endl ;
   cout << "   Parameter ans is: " << ans << endl ;
}