Your problem is that you never use the p value, but instead you use the exponent which may be negative in your loop, so instead of iterating it will stop as 1 will be greater than any negative value
Here's how it should be:
1 2 3
for (int i = 1; i < abs(exponent); ++i)
result*=base;