Question: Language: C++ Write a user-defined function called power() that takes a double value for n and an int value for p, and returns the result

Language: C++

Write a user-defined function called power() that takes a double value for n and an int value for p, and returns the result as a double value. Use a default argument of 2 for p, so that if this argument is omitted, the number will be squared. Write a main() function that gets values from the user to test this function. Do not use a math library.

int main() { //add code here return 0; } double power(double n, int p) { //add code here return pow; }

Sample outputs: Enter the number: 4 Do you want to enter power (y/n)? y Enter the power to be raised: 3 4 ^ 3 (4 raised to the power 3) = 64

Enter the number: 4 Do you want to enter power (y/n)? n 4 ^ 2 (4 raised to the power 2) = 16

Enter the number: 4 Do you want to enter power (y/n)? a Invalid choice Do you want to enter power (y/n)?

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!