Output is incorrect, am I missing the header ?

Asked By 7060 points N/A Posted on -
qa-featured

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;
}
SHARE
Best Answer by Puckett Buckner
Answered By 0 points N/A #80697

Output is incorrect, am I missing the header ?

qa-featured

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…

Best Answer
Best Answer
Answered By 0 points N/A #80699

Output is incorrect, am I missing the header ?

qa-featured

 

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 – 

http://msdn.microsoft.com/en-us/library/da60x087.aspx

 

That should resolve your issue.

Regards,

Puckett

Login/Register to Answer

Related Questions