Answer the question
In order to leave comments, you need to log in
Why does it give an error - ambiguous call to an overloaded function?
There is an elementary program.
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{
int x1, x2, y1, y2;
double l;
cin >> x1 >> x2 >> y1 >> y2;
x1=x2-x1;
y1=y2-y1;
l=sqrt((x1*x1)+(y1*y1));
cout << fixed << setprecision(2) << l;
return 0;
}
Answer the question
In order to leave comments, you need to log in
1. Instead of , in C++ you need to use . It's more performant in some cases, and there are more features for C++.
2. Why introduce , if we still calculate ? Then the program will not go crazy with large coordinates.
3. Instead , you can use without loss of performance.
Total:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
double x1, x2, y1, y2;
cin >> x1 >> x2 >> y1 >> y2;
cout << fixed << setprecision(2) << sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question