Error 1 error C2668: 'pow' : ambiguous call to overloaded function

Error 1 error C2668: 'pow' : ambiguous call to overloaded function (line 22)

I've try to chage all about pow, but I can't find the error, help please!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;
#include <math.h>

void main()
{
	double angulo,resul;
	short orden;
	cout<<"Inserete el angulo (radianes): ";
	cin>>angulo;
	cout<<endl;
	cout<<"Orden del polinomio de Taylor?: ";
	cin>>orden;
	double fac;
	double j = 1.0;
	for (int i = 0;i<=orden;i++,j += 2)
	{
		for (fac = j;fac>=1;fac--)//igual hay quer quitar la igualdad
		{
			fac *= j;
		}
		resul += ((pow(angulo,j)/(fac))*pow(-1,i+2));
	}
	cout<<endl;
	cout<<"sin("<<angulo<<") = "<<resul<<"."<<endl;
}
First, include <cmath> instead of <math.h>.

Second, which pow? Debug that by splitting the equation:
1
2
3
4
5
6
7
resul += ((pow(angulo,j)/(fac))*pow(-1,i+2));

==>

auto p1 = pow( angulo, j );
auto p2 = pow( -1, i+2 );
resul += ( p1 / fac ) * p2;

When you know the ambiguous call, then you can look at the types of the parameters in that call.
-1 is an int. i+2 is an int. Your system does not have pow(int,int) and the alternatives all look equally "close enough". Compiler cannot decide.

However, why pow()? -1 to any positive integer power should produce either 1 or -1. All you want to know, is the sign. (i+2) is either odd or even. That determines the sign.
Thats it!!!, but now I have another problem when i'm executing it compiles ok, and when i start wihout the debug it starts

1st asks the angle
2nd the order of Taylor
3rd IT DOESN'T MAKE NOTHING ='(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace std;
#include  <cmath>

void main()
{
	double angulo,resul;
	resul = 0;
	angulo = 0;
	short orden;
	cout<<"Inserete el angulo (radianes): ";
	cin>>angulo;
	cout<<endl;
	cout<<"Orden del polinomio de Taylor?: ";
	cin>>orden;
	double fac;
	double j = 1.0;
	for (double i = 0;i<=orden;i++,j += 2)
	{
		for (fac = j;fac>=1;fac--)//igual hay quer quitar la igualdad
		{
			fac *= j;
		}
	double p1,p2;
		//resul += ((pow(angulo,j)/(fac))*pow(-1,i+2));
		p1 = pow( angulo, j );
		p2 = pow( -1, i+2 );
		resul += ( p1 / fac ) * p2;
	}
	cout<<endl;
	cout<<"sin("<<angulo<<") = "<<resul<<"."<<endl;
}
I repeat: do not use pow for calculating the sign.
Do not use floating point values for iteration counters (i, j, fac). Cast, when necessary.

There is no "nothing". If you do suspect a loop, then debug by printing something on every iteration.
execute trough a debugger and interrupt the program.
the debugger would show the next line to be executed
Topic archived. No new replies allowed.