Yes that is because you are using a single
=
and not a
==
to check if it is equal. So you are equaling raise to 0 in the first part, then equaling it to 1 in the second. Which is why you get 3.
1 2 3 4 5
|
if(raise=0) //Should be if(raise==0)
return (1);
else if (raise=1) //Should be else if(raise==1)
return base;
|
Also, remember to set your counter to 1. If it is set at 2, which is what you have now, then you will have an incorrect calculation.
Suppose we go with what you have and we start counter at 2, then you want to raise 5 by a power of 3
raise
. In your
while (counter<=raise)
loop, counter goes up to raise. Since counter is 2, it will be 3 after one round (
counter++
). You will end up with 5*5=25, and not 5*5*5=125. Well, actually it would work in your case since you used
<=
and not a single
<
, but I just don't see the point of counter being initialized at 2.