Initialize two arrays that specify n points with coordinates (X, Y) in two-dimensional space. Describe the function that finds the distance between two arbitrary points.

At start, the following code gives out -80, then 112, then 160. Please help me, please, what is the error?

#include "stdafx.h" #include "iostream" #include <math.h> using namespace std; int main() { setlocale(LC_ALL, "Russian"); int *x=new int [5] {1, 4, 6, 2, 1}; //созданиС массива ΠΈΠ· 5 ΠΊ-Ρ‚ Ρ… int *y=new int [5] {6, 7, 8, 9, 10}; //созданиС массива ΠΈΠ· 5 ΠΊ-Ρ‚ Ρƒ cout << "РасстояниС ΠΌΠ΅ΠΆΠ΄Ρƒ двумя Ρ‚ΠΎΡ‡ΠΊΠ°ΠΌΠΈ:" << distance(x,y) << endl; } int distance(int *x,int* y, int size) // { float d; d = sqrt(pow((x[1] - x[0]), 2) + pow((y[1] - y[0]), 2)); return d; } 
  • Another hello from the wild way of doing using namespace std; ... - AnT
  • and how else can you? I'm new - marsianin
  • Not understood. Newbie or novice, you are done using namespace std; for some purpose. Which one - AnT
  • He did this with the goal of looking scientific. (copied from somewhere) - Igor

1 answer 1

In fact, once you did not declare distance before use, the compiler searched-searched, and you used the distance from the standard library - look for the distance between two iterators ...

Add

 int distance(int *x,int* y); 

before int main()() .