Quick recursive function question

I can't figure out why this is not returning the correct result.

1
2
3
4
5
6
7
8
  int  raiseToPowerR(int base, int exponent)  // assume exponent > 0
{
    
    if (exponent <=1) return 1;
    
    return  base * raiseToPowerR(base, exponent-1);
    
}


Thanks for looking.
Your base case on line 4 needs to be tweaked. Right now, any number raised to 1 is going to return the value 1 - which isn't correct. That's throwing your result off.
Oh duh, thanks man.
Topic archived. No new replies allowed.