Hello everyone and thank you for taking your time to read this post.

I came across a rather confusing problem for me. I have been given a prototype of the function I am **not** allowed to change and it has to perform the following task:

If we call the function three times with the number 2 as parameter, it should return **2,4,8**(the exponents increase with each call). However, if we call it with another number, the exponent resets and starts back from one. For example: When we call the function three times with number 2 as the parameter, it returns.**2,4,8**. But after that, if we call it with a different number(say 5) the function should return **5,25,125**. and so on. To summarize, the exponent count has to reset to 1 each time the function is called with a different number.

Now here comes the catch: here's the prototype:

Code:

double power(double x)

Note that I can't use pointers because I can't send a pointer as a parameter. I managed to do something like this:

Code:

double power(double x) {
static int exponent = 1;
return pow(x,exponent++);
}

But how do I reset the exponent back to 1 when the function is called with another number? And are static and global variables the only way to do this?

Thanks once again!