Write a C++ function that get two numbers from the user and displays the result of first number raise to the power of second number using do while loop.
#include <iostream>
#include <conio.h>
#include <iomanip>
usingnamespace std;
int func_power (int , int);
int main () {
int x,y;
int r;
cout << "Enter Two Numbers" << endl;
cin >> x >> y;
r = func_power(x,y);
cout << "result " <<r;
return 0;
}
int func_power (int a,int b) {
int result = 1;
int counter = 1;
do {
result = result * a;
counter++;
}
while (counter <= b);
}
The Program is supposed to give me the result after a number is raised to a power but here it is not giving me the right answer
FOR EXAMPLE
If I type first number as 5 and second number as 2
The answer is 3 HOW?