#include <stdio.h>

// Power function we implemented in class.
float power(float base, unsigned int ex) {
  float retVal = 1.0f;
  unsigned int i;
  for(i = 0; i < ex; i++)
    retVal = retVal * base;
  return retVal;
}

// Functions do not always have to take in parameters. If you have no parameters to
// pass into the function  then use () or (void). Also, a function does not need to
// ALWAYS return a value. If a function does not return a value
// (e.g., in this case is does not), then void is used as its return type.
void calculatePower() {
  float base;
  unsigned int ex;

  printf("Enter base: ");
  scanf("%f", &base);

  printf("Enter exponent: ");
  scanf("%u", &ex);

  /* Notice how I needed to define the power function above the
     calculatePower function in order to use it. This is important
     to do. For now, if you write a function and you want to
     use it in another function you need to implement it before
     you call it in another function. Thus, I want to call power
     in the calculatePower function then I need to make sure I
     implemented the power function before the calculatePower
     function.
  */
  float powerVal = power(base, ex);

  printf("%f^%d = %f\n", base, ex, powerVal);
}

int main(void) {
  calculatePower();
  return 0;
}
