Question: In c++, Write code to complete RaiseToPower(). Sample output if userBase is 4 and userExponent is 2 is shown below. Note: This example is for

In c++, Write code to complete RaiseToPower(). Sample output if userBase is 4 and userExponent is 2 is shown below. Note: This example is for practicing recursion; a non-recursive function, or using the built-in function pow(), would be more common.

4^2 = 16 

#include using namespace std;

int RaiseToPower(int baseVal, int exponentVal){ int resultVal = 0;

if (exponentVal == 0) { resultVal = 1; } else { resultVal = baseVal * /* Your solution goes here */; }

return resultVal; }

int main() { int userBase = 0; int userExponent = 0;

userBase = 4; userExponent = 2; cout << userBase << "^" << userExponent << " = " << RaiseToPower(userBase, userExponent) << endl;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!