Need help with call functions!

So basically my call function doesnt work when it gets to a certain step in my main function.

-An error that I get is "No matching function for call to 'power'."

CODE:
#include <iostream>
#include <cmath>

using namespace std;

int power(int,int);
string print(string,int);
int main()
{
int x = 3;
x = power(x, 3);
print("Value of x after step 1 is ", x);

x = power(x, 2);
print("Value of x after step 2 is ", x);

x = power(x);
print("Value of x after step 3 is ", x);

x = power(x, 101);
print("Value of x after step 4 is ", x);
x = power(3, -5);
print("Value of x after step 5 is ", x);
x = 10;
x = power(x);
print("Value of x after step 6 is ", x);

return 0;

}

int power(int num1, int num2)
{

int value;
return value = pow(num1,num2);

}
string print(string a, int b)
{
cout << a <<b<< endl;
}



per-declare the functions:
1
2
int power(int num1, int num2);
string print(string a, int b);


Also, you cannot define a string as an integer, use to_string.
The error message is coming from the line:

x = power(x);

which occurs twice in your code. Your power function takes two parameters, not one.

Also, your print function is declared to return a string, however you return nothing in the the body of the function. It doesn't appear that there is anything to return so you could just change the declaration and implementation of your print function to:

void print(string,int); and

1
2
3
4
void print(string a, int b)
{
cout << a <<b<< endl;
}


Is there some reason you are defining your own power function instead of using the library function pow directly?

Topic archived. No new replies allowed.