# Thread: problem with function help

1. ## problem with function help

I have another problem I've spent a long time trying to solve. I know it's probably really simple but I cannot get it to work.

Here's the problem:
Write the definition of a function powerTo , which receives two parameters. The first is a double and the second is an int . The function returns a double .

If the second parameter is negative, the function returns 0. Otherwise, it returns the value of the first parameter raised to the power of the second.

Here's my attempt:

Code:
```double powerTo(double base, int power)
{
int n;
for (int k = 1; k < n; k++) {
if (power < 0)
return base *= power;
else
return 0;
}
}```
This is the error message I get from codelab:

Code:
`Sometimes your code doesn't return a value.`
I really would appreciate someone's help on this, I think it's something pretty easy but I'm just lost on this one.

2. I think you need to work out the logic on this one. Let's go through the steps of raising a number to a power. We know that raising to a power means multiplying by itself a number of times
2^3 = 2 * 2 * 2
Let's keep in mind that a number to the zeroth power is one
2^0 = 1
2^1 = 1 * 2
2^4 = 1 * 2 *2 * 2 * 2
So now for the logic of the function you're writing. First thing, check to make sure power is not < 0. If it is < 0 then return 0. Ok. Now we want a double that we are going to return. You need to initialize it to a certain number(you need to figure out which number for yourself). Then run a loop. The for loop you have set up is fine. For each cycle, you will want to multiply your return value not by the power but by the _______. After the loop return the return value. Good luck!