Hello! I'm new to C++ and learning about functions. I came up with no errors while compiling and linking, but it couldn't execute. I think it was a syntax error or something. I'm supposed to write a function integerPower (base, exponent) that returns the value of base exponent.
The code:
#include <iostream>
using std::cout;
using std::endl;
int integerPower(int, int);
int main ()
{
int base = 3;
for (int exponent = 1; exponent <= 10; exponent++)
cout << base << "^" << exponent << " = "
<< integerPower(base, exponent) << endl;
return 0;
}
int integerPower(int base, int exponent)
{
return base * integerPower(base, (exponent - 1));
}
Thanks!
The code:
#include <iostream>
using std::cout;
using std::endl;
int integerPower(int, int);
int main ()
{
int base = 3;
for (int exponent = 1; exponent <= 10; exponent++)
cout << base << "^" << exponent << " = "
<< integerPower(base, exponent) << endl;
return 0;
}
int integerPower(int base, int exponent)
{
return base * integerPower(base, (exponent - 1));
}
Thanks!