// Dr. Ramsey #include using namespace std; //function prototype double my_power(double x, int n); void input(double &x, int &n); int main() { double xin; int nin; input(xin,nin); cout << my_power(xin,nin) << endl; return 0; } void input(double &x, int &n) { cout << "Please input a real value x for x^n: "; cin >> x; cout << "Please input a positive integer value n for x^n: "; cin >> n; //disallow negative values in the input? /* while( n < 0) { cout << "Error: please input a positive integer: "; cin >> n; } */ } //a function that raises a double x to the power of n double my_power(double x, int n) { //some recursive functions have a case to catch invalid input if(n < 0) { cout << "Error to my_power, n < 0" << endl; return 0; // "bogus" return value for error case } //all recursive functions have at least one base case if(n == 0) return 1; //all recursive functions have at least one case where the function //calls itself return x * my_power(x,n-1); }