0

HI....

I'm doing this question...

**Question**

Using a non-void function with parameters, write a complete C++ program that prompts the user for the Cartesian coordinates of two points (x1, y1) and (x2, y2) and displays the distance between them computed using the formula:

distance = sqrt( (x1-x2)^2) + ((y1-y2)^2)...

and i came out with this code :

```
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double distance(double x1,double x2,double y1,double y2);
int main () {
cout<<"Enter The First Coordinate :";
double x1,y1;
cin>>x1>>y1;
cout<<"Enter The Second Coordinate :";
double x2,y2;
cin>>x2>>y2;
cout<<endl;
cout<<"The Distance Between Two Coordinate Is :"<<distance(x1,x2,y1,y2);
}
double distance(double x1,double x2,double y1,double y2)
{
return sqrt((2*(x1-x2))+(2*(y1-y2)));
}
```

this code run smoothly but not until it displayed the answer...

because when it display the distance,i always got the wrong answer and sometimes it display the **NaN**....

i dont know whats wrong with my code....

could somebody figure it out??

Thank You....