Recursive function

I need to make a recursive function that returns a number to a entered power.
Such as 3 to the 3rd power is 27.

Here's my code so far. But I don't know what to put for the return that would make it recursive.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

int PowerFunction(int number, int power);  //prototype function

int main()
{
	int number, power, result;
	std::cout << "Enter number and power\n";
	std::cin >> number >> power;

	result = PowerFunction(number, power);
	std::cout << "Result: \n" << result;
}

int PowerFunction(int number, int power) //defined function
{
	return (what to put here?)
}
Last edited on
Do you know what a recursive function is?
Then how would you split up the term 3³ so it still contains a power, but gradually becomes simpler?
Yeah, and that's what you're supposed to put in there.
Last edited on
I know what a Recursive function is. But I don't know the code i'd have to put for it to call itself.
Then proceed to answer the second question.
What is the definition of recursion? See recursion.

1
2
3
4
5
6
7
int PowerFunction( int number, int power )
{
  if( power > 1 )
    return number * PowerFunction( number, --power );
  else
    return number;
}
@binarybob350: Don't just post solutions.
Topic archived. No new replies allowed.