Geometry Circle Distance Problem

I am wondering why I can't input the second set of numbers in my code. After I enter the first set of numbers and press enter, it solves the problem, without letting me input my second set of numbers.

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
#include <iostream>
#include <cmath>
#include <ctime>
#include <iomanip>
using namespace std;

int main()
{
	double x1;
	double x2;
	double y1;
	double y2;
	cout << "Enter point 1 (latitude and longitude) in degrees: " << endl;
	cin >> x1 >> y1;

	cout << "Enter point 2 (latitude and lantitude) in degrees: " << endl;
	cin >> x2 >> y2;

	x1 = x1 * (3.14159 / 180);
	y1 = y1 * (3.14159 / 180);
	x2 = x2 * (3.14159 / 180);
	y2 = y2 * (3.14159 / 180);

	double d = 6371.01 * acos(sin(x1) * sin(x2) + cos(x1) * cos(x2) * cos(y1 - y2));

	cout << "The distance between the two points is " << d << " km" << endl;

	return 0;
}
You mean the program only let you input values for x1 and x2? In that case please show us the input you're feeding the program because it seems to work fine for me.

If you instead mean you want the program to restart so that you can input another two points, then you should use some kind of loop. http://www.cplusplus.com/doc/tutorial/control/#loops
Last edited on
No I mean the program is only letting me input x1, y1 and then when I press enter it outputs the result of the distance without letting me input x2 and y2. The number I am using are as follow:

Point 1: 39.55, -116.25

Point 2: 41.5, 87.37

The result should be: 10691.79183231593
Don't use a comma to separate your input, use spaces.
Topic archived. No new replies allowed.