2008 Visual C++ errors

I have tried a program for the first n*p perfect squares and there are some problems like :

error C2668: 'sqrt' : ambiguous call to overloaded function
;could be 'long double sqrt(long double)';
'float sqrt(float)';double sqrt(double)' etc ;
then I changed i from int to float/double and that did not help me at all. Also I have seen on this forum this function : static_cast<double> and this did not work either .
If you can help me with this I will really apreciate . Thanks


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream>  
#include<conio.h>
#include<math.h>
using namespace std;
void main(){
	int n,p,i;
   cout<<"n= "; cin>>n;
   cout<<"p=";cin>>p;
   
   for(i=2;i<=n*p;i++)
     if(i%sqrt(i)==0))
		 cout<<i;

getch();
}
Last edited on
You don't need to find the square root for this, do you?

1
2
3
4
5
6
7
8
9
#include <iostream>

int main()
{
    int n = 10 ;
    std::cout << "n? " ;
    std::cin >> n ;
    for( int i = 1 ; i<=n ; ++i ) std::cout << i*i << '\n' ;
}
Thanks.

But why did you make n=10 ( I am not familiar with this type of code )
> But why did you make n=10

Initializing n with 10 is really unnecessary; it doesn't achieve anything.

I did it because in old compilers, if std::cin >> n fails, the value of n would remain unchanged; and 10 becomes a default value to be used in case of input failure.

> I am not familiar with this type of code

What part of the code are you unfamiliar with?
Topic archived. No new replies allowed.