distance between points

not sure how to complete this. would it be ok to create and use one more distance function with different arguments. Using VS 15

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "stdafx.h"
#include <iostream> //cin cout definitions
#include <stdio.h>  //scanf printf definitions
#include <math.h>   //library containing sqrt
using namespace std;


//Function prototype - Calculates the distance between coordinates
double distance(int x1, int x2, int y1, int y2, int x3, int y3);


int 
main(){
	
   int x1;   //input - x coordinate of point A
   int y1;   //input - y coordinate of point A
   int x2;   //input - x coordinate of point B
   int y2;   //input - y coordinate of point B
   int x3;   //input - x coordinate of point C
   int y3;   //input - y coordinate of point C
   int slope;
	
	
   //Get coordinates x, y
   printf("\nEnter two integers as the coordinates for the first point> \n");
   cin >> x1 >> y1;
	
   printf("\nEnter two integers as the coordinates for the second point> \n");
   cin >> x2 >> y2;
	
   printf("\nEnter two integers as the coordinates for the third point> \n");
   cin >> x3 >> y3;
	
   //Call distance and display results
   printf("\nThe distance between Points 1 and 2 is: %d \n" );
   printf("\nThe distance between Points 1 and 3 is: %d \n" );
   printf("\nThe distance between Points 2 and 3 is: %d \n" );
	
}  //end main


//Function definitions
double 
distance(int x1, int x2, int y1, int y2, int x3, int y3) {

	z = ((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));

	v = ((x3 - x1)*(x3 - x1) + (y3 - y1)*(y3 - y1));

	w = ((x3 - x2)*(x3 - x2) + (y3 - y2)*(y3 - y2));

	double distance_1 = sqrt(z);
	double distance_2 = sqrt(v);
	double distance_3 = sqrt(w);

}




/*   double getDistance(struct Point a, struct Point b)
    {
	double distance;
	distance = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) *(a.y - b.y));
	return distance;
    }     */

I'd suggest, don't try to handle three different points at the same time. Use a function which returns the distance between just two points, and call it several times if there are several points.

I also would think the commented-out struct Point could be usefully employed throughout the code.
thanks buddy
Topic archived. No new replies allowed.