0
#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

2
Contributors
1
Reply
4
Views
5 Years
Discussion Span
Last Post by NathanOliver
0

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

Edited by NathanOliver

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.