# Distance between 2 points - multiple times

 cheeky carter · January 4, 2015 as part of my computer coursework, I ask the user to input the number of corners a fence will have (between 3 and 10) and ask them to input the co-ordinates. i then have to find the distance of each side. How do i do this? I know how to find the distance between 2 points but how do i get it to keep calculating the distance?#includeusing namespace std;int main(){ int corners = 0;     double x[10], y[10];  double dist;  double Distance; //enter no. of corners while (corners < 3 || corners>10){ cout << "Please enter the number of corners, (between 3 and 10) of the fence:" << endl; cin >> corners; } //Ask user to input co-ordinates of the corners  for (int i = 0; i < corners; i++){ cout << "Please input positive x and y values for corner " << i + 1 << endl; cin >> x >> y; } //Calculate distance int j = corners - 1; for (int i = 0; i < corners; i++){ dist = (x - x)*(x - x) + (y - y)*(y - y); j = i;        Distance = sqrt(dist); } //Print result cout << "Distance between these points = " << Distance << " metres." << endl; return 0;}

## Replies

 cheeky carter · January 5, 2015 thank you very much!! Stan Botha · January 5, 2015 for some reason, inserting the code above some information got lost. Stan Botha · January 5, 2015 #include#includeusing namespace std;int main(){ int corners = 0; double x[10], y[10]; double dist; //enter no. of corners while (corners < 3 || corners>10) {     cout << "Please enter the number of corners, (between 3 and 10) of the fence:" << endl; cin >> corners; } //Ask user to input co-ordinates of the corners for (int i = 0; i < corners; i++){ cout << "Please input positive x and y values for corner " << i + 1 << endl; cin >> x >> y; } //Calculate distance int j = corners - 1; for (int i = 0; i < corners; i++){ if(i
• 1

## C++

120,926 followers