Help - why is there an issue with the power function?
the error states:
: error C2668: 'pow' : ambiguous call to overloaded function

void compute(int integer)
{
	cout << integer;
	int value = 9;

	while(value > 0)
	{
		cout << ++ integer;
		int square = pow(integer,2);
		cout << square;
	}
}

pow is overloaded for multiple types, and all of them can be converted to from int. An easy way to fix the problem is to force the second argument to double:

int square = pow(integer,2.0);

pow is overloaded for multiple types, and all of them can be converted to from int. An easy way to fix the problem is to force the second argument to double:

int square = pow(integer,2.0);

ok thank you - at first it was giving me another error but now it is working fine. Do you know if there is a way to combine this using only one function and one while loop? I tried doing it but it was integrating the squares with the integers and it needs to print 1 through 10 and then the squares, 1 through 100.

void compute(int integer)
{
	int counter = 9;
	while(counter >= 0)
	{
		cout << integer << " ";
		integer++;
		counter -=1;
	}
}
void square(int integer)
{
	int counter2 = 9;
	while(counter2 >= 0)
	{
		cout << pow(integer,2.0) << " ";
		integer++;
		counter2 -=1;
	}
}

If you don't mind two columns instead of two rows then this works:

void square(int integer)
{
	int counter2 = 9;
	while(counter2 >= 0)
	{
		cout << integer << '\t' << pow(integer,2.0) << '\n';
		integer++;
		counter2 -=1;
	}
}

ok thank you :-D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.