/********************************************************************** Ed Yakabosky CSE 103 Section 003 This is the third lab program for CSE 103. This program is designed to take parameters as two integers x and y such that x is nonzero and returns x^y. input: integers x and y. output: **********************************************************************/ #include using namespace std; double power(int x, int y); // Function prototype. int main() { // Initializes variables. int x = 0; int y = 0; cout << "Please enter a value for x: "; cin >> x; cout << endl; while (x <= 0) // If x not more than 0, this error statement outputs. { cout << "Please re-enter x. It must be greater than 0."; cin >> x; cout << endl; } cout << "Please enter a value for y: "; cin >> y; cout << endl; cout << "x^y is roughly: " << power(x, y) << "!!!!!!!!" << endl; return 0; } /* This function computes a base, x, to an exponent, y. Its parameters are input integer values for x and y; the statement is not a void statement so we do not need them to be reference parameters. The function returns a double x^y. */ double power(int x, int y) { if (y == 0) // Returns 1 if y is 0. { return 1; } if (y == 1) // Returns x if y is 0. { return x; } if (y > 1) // Returns x and recurses the power function if y is greater than 1. { return x * power(x, y - 1); } else { // Returns 1 divided by a negative y. This will be a decimal, so function returns // a double. return (1/power(x, -y)); } }