Can't Debug Need some guidance [Do-While Loop]

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
20
21
22
23
24
25
 
#include <iostream>
#include <conio.h>
#include <iomanip>
using namespace 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?
you forgot a return statement, and result in main is therefore random.

add return result to your function.
Your func_power function doesn't return anything.
Lol @ user name ^^^ :)
(Just struck me funny, we were typing at the same time from the message stamp).
Thank you Guys but I had figured out a long time ago before you guys posted your comments xD

But still
Thanks a lot
Topic archived. No new replies allowed.