Asked By
anonymous
7060 points
N/A
Posted on - 09/20/2011
Hi,
I'm using Visual Studio 2008, and please take a look at the code attached.
It doesn't compile correctly as it builds fails.
And the error message appears : error C2668: 'Pow' : ambiguous call to overloaded function. (I attached it)
Any idea what happens ?
Thanks
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int N1;
cout<<"Enter the first number (a):";
cin>>N1;
int N2;
cout<<"Enter the second number (b):";
cin>>N2;
cout<<"a^b = ";
cout<<pow(N1 , N2)<<endl;
return 0;
}
Output is incorrect, am I missing the header ?
I think there is a simple solution, try including math.h instead of cmath and make your "integers" doubles. Like: double n1; double n2; or float n1; float n2; I don't really remember how was the correct declaration in C…
Output is incorrect, am I missing the header ?
Hello,
That’s pretty interesting.
First, use <cmath> and not <math.h>
Second, “pow” is not an integer rather it takes a floating point type number.
You can just try casting your statements.
Depending on what output you wish, there are a lot of reasons that the function may not work.
I would recommend visiting on this website for the different error codes related to programming –
https://msdn.microsoft.com/en-us/library/da60x087.aspx
That should resolve your issue.
Regards,
Puckett