You pass the power and result of base * 10 to a recursed function, decrementing it the power with each recursion and then return the result when it hits 0 (or would it be -1? not sure which, but that is how I would do it).
You know how to raise something to the power of something else, don't you? (you should know if you passed elementary school). Well, then you know how to write a program that does that.
base starts at 10, since that is the base you're using.
You have a power that is input by the user.
You can't just multiply 10 * 10 because the answer would always be 100. You need to carry the result of the calculation into the next run the function.
You can't recurse indefinitely, so you pass the number representing the power as a counter and subtract 1 for each time you raise the base by 10.
@Subzero030201
That's almost the answer. The only problem is that you're not actually multiplying 10 by the previous answer, but always just by ten... You're always going to get 100 back.
Either make number static or multiply it by the return value of recur:
int raiseten( int, int );
int main( )
{
int base = 1;
int exponent;
int result = 0;
cout << "Enter an exponent to raise 10 by: ";
cin >> exponent;
result = raiseten( base, exponent );
cout << result;
cin.ignore();
cin.get();
}
int raiseten( int base, int power )
{
if (power == 0)
return base;
elsereturn raiseten( base * 10, --power );
}
I'm sure this could be adapted. It certainly should be changed so that you're not passing 1 to the function but the actual and power and a 1 should be returned if it is a power of zero. I think three parameters would be needed in such a case: result, base, power.