What's new

question for the c++ programmers- recursion

mesman00

What's that...?
damn, this is a simple problem i'm havin in c++ with recursion. its wicked pissing me off, so i decided to ask here. i need to write a program that asks the user for a number and a power. Then, i need to write a recursive function that takes the number the user entered and raises it to the power the user entered. For example, if the user enters a number of 2 and a power of 4, the function will return 16. now, help me please! i've been goin at it for a while, and i just can't seem to come up with it. here's the code i have, it's really just the main function, because the only other one is the power function (where the recursion will occur), the one i'm havin a little trouble with.

// Exercise 7
#include <iostream.h>

int power(int number, int raise);

int main()
{
int number;
int answer;
int raise;

cout << "Enter a number: ";
cin >> number;
cout << "Enter a power to raise the number to: ";
cin >> raise;
cout << endl;

answer = power(number, raise);

cout << number << " raised to the " << raise << " th power is equal to " << answer << endl;

return 0;
}

int power(int number, int raise)
{
HELP NEEDED HERE
}
 

Top