Trouble finishing a function/

Hello, I am having trouble writing my code for the problem which states:

"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."

I feel as if everything I have written is correct, but every time I submit my code, it says that the value returned is incorrect, what errors could I be making?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  double powerTo(double x, int y)
{
	if (y<0)
{
	return 0;
}
else

{
	double value=x;
   
 for(int z=1; z<y; z++)
	
 	{
		value*=x;
	}

	return value;
	
	}
}
line 18 return value should be after the second brace of for loop (after line 20) and not inside the for loop.
I agree with shadder, the return should not be within the for loop. I would also fix your braces, it was a little confusing trying to read where everything was beginning and ending.
Topic archived. No new replies allowed.