### Exponential Power Function This is my assignment, please look at my program and give me any tips? (I'm not quite sure I did it right). Main is supposed to be sending values to the power function.

Write a prototype and function for calculating powers of numbers.
This version should have an integer return type and take two integer inputs, for the base and the exponent. It should do the following:
• handle negative bases
• return an error on negative exponents (we’re not doing those yet)
• handle zero exponents
Call your function from a nested loop in main(), which calls the function using every combination of negative, zero and positive numbers for both base and exponent. This will test your function without the user having to input all the data.
Any code which calls the library pow() function will lose half of the assignment points.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273`` ``````#include using namespace std; int power (int, int); int main() { int size = 10; int test[size]; int base; for (base = -2; base < 4; base += 2) { for (int expon = -2; expon < 4; expon += 2) { cout << base<< " " << expon << " " << power(base,expon) << endl; } } cout << endl; return 0; } int power (int num, int raisedTo) { int product; if (raisedTo < 0) { cout << "Please enter a non negative exponent. " << endl; } else if (raisedTo == 0) { product = 1; return product; } while (num > 0) { for (num = num; num <= raisedTo; num++) { product = num * num; return product; } } while (num <= -1) { if(raisedTo % 2 == 0) { for (num = num; num <= raisedTo; num++) { product = num * num; return product; } } else for (num = num; num <= raisedTo; num++) { product = num * num * -1; return product; } } }`````` well your code looks complicated - you only need one loop

something like this

 ``123`` ``````product = 1; for(i=0;i

Topic archived. No new replies allowed.