#include <iostream>
#include <string>
using namespace std;

double distance(double x[],double y[]){
     return sqrt((y[0]-x[0])*(y[0]-x[0])+(y[1]-x[1])*(y[1]-x[1]));
     } 
int main(){
    double d;
    double x[]={1,2};
    double y[]={4,3};
    cout<<distance(x[2],y[2])<<endl;
   //cout<<d<<endl;
   cin.get();
   return 0;}

why wont it work
I also tried

        d=distance(x[],y[]);
        cout<<d<<endl;

but it wont work either

The pbroblem is that you are passing the arrays to the function wrong. If you want to pass the arrays it will look like this

cout << distance(x, y) << endl;

Since your function is set up to take an array you just pass the entier array by using the name. what you are doinW is passing the value one past the end of the array

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.