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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <conio.h>
usingnamespace std;
int main() {
int n,p,r;
int counter = 1;
cout << "Enter " << endl;
cin >> n>>p;
do {
r = n*1;
counter++;
}
while (counter <= p);
cout << r;
}
#include <iostream>
usingnamespace std;
void power_func();
int main() {
power_func();
}
void power_func()
{
int n,p,r; ///let your variables be descriptive
int counter = 1;
cout << "Enter " << endl; ///use a descriptive message
cin >> n>>p;
do {
r = n*1; ///this is wrong should be like num1 *= num2
counter++;
}
while (counter <= p);
cout << r;
}