kmf
kmf

Reputation: 21

Undeclared identifier/array

I'm getting this error array1 undeclared (first use this function) , array1 undeclared (first use this function) and [Warning] converting to int from double

Here's the code:

#include<conio.h>
#include<math.h>
using namespace std;

int main(){
double dist(double array1[4], double array2[4]);
{
    double Sum;
    double distance;

    for(int i=0;i<4;i++)
    {
        cout<<"Enter value of first coordinate";
        cin >> array1[i];
        cout<<"Enter value of second coordinate";
        cin >> array2[i];

        Sum = Sum + pow((array1[i]-array2[i]),2.0);
        distance = sqrt(Sum);
    }
        cout << "DISTANCE: " << distance;
    return distance;
}
}

I don't understand on where to fix this error. Could somebody help with this?

Upvotes: 1

Views: 1564

Answers (1)

xis
xis

Reputation: 24850

  1. I have not seen conio.h for centuries. I am assuming it is Turbo C++? Use #include <iostream> instead.
  2. You are declaring the function dist inside main. C++ does not allow this unless you use C++11 lambda grammar. Move dist out of main, remove the semicolon of the function declaration line.

Upvotes: 1

Related Questions