powfun Using loops

Hi everyone,
I'm just stuck on a powfun function problem. It just states to enter an integer, enter a positive integer power, and find the result, i.e 2^3=8. I just don't know how to go about using a for loop in the powfun function. Here's what I have [I know it's not correct but I'm trying to find the correct "conditions" inside for ()]:

void powfun (int a, int b)
{
long int result;

for (result = a; ; result++)
result = result * a;
cout << result;

return;
}
BTW, I know that code is not correct. Feel free to correct. :D
int powfun(int a, int b)
{
int p = 1;
for (int i=0; i<b; i++)
{
p *= a;
}

return p;
}

You have to take care of data type overflow, here i've used integer only.

Gorav
http://www.kgsepg.com
Topic archived. No new replies allowed.