error: Ambiguous call to overloaded function

So I write this program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <cmath>
using namespace std;
int main() 
{
	int n; 
	int i=2; 
	int prime = true; 
	cout << "Pick a number: ";
	cin >> n;
	while (i <= sqrt(n)) 
	{ 
		if (n % i == 0) 
			prime = false; 
		i++; 
	}
	if (prime)
	cout << "Number is prime." << endl;
	else
	cout << "Number is not prime." << endl;
	system("PAUSE");
	return 0;
}


And i get this error: error C2668: 'sqrt' : ambiguous call to overloaded function

I don't know if it's because of any mistake I made (I can't find one), or what it is. I'd appreciate your help.
There is no sqrt overloaded for an integer argument there are only for float, double and long double.
You could make it i <= sqrt(float(n)).

Note though that instead of i <= sqrt(n) you could have i*i <= n.
Last edited on
Topic archived. No new replies allowed.