Вычисление расстояния между двумя широтами и долготами, которые сохраняются в текстовом файле?
Я огляделся и до сих пор не смог найти ничего, что могло бы мне действительно помочь! Я написал программу для расчета расстояния между двумя городами, используя их широты и долготы, данные о городах сохраняются в файле, а затем загружаются в мою программу в BST! Пока что все работает отлично, кроме случаев, когда я запускаю коды, которые, как предполагается, для вычисления расстояния, я получаю одинаковый ответ для каждого города! Я не совсем уверен, почему я продолжаю получать один и тот же ответ для каждого города! Пожалуйста, помогите указать мне правильное направление?
вот коды для расчета расстояния
<code>#include <cmath> #define pi 3.14159265358979323846 string userResponse; float globalLat1, globalLon1, globalLat2, globalLon2; for(int j= 0; j < 2; j++){ string whatever; if (j==0){ bool hasbeenfound = false; do{ //ask the user to enter their first city of their choice whatever = "first "; cout << "Enter your " + whatever + "City" << endl; cout << "-------------------" << endl; cin >> userResponse; cout << endl; if (Cities->search(userResponse)) //check if the entered city already exist { hasbeenfound = true; } else{ cout << "City not Found" << endl; cout << endl; } //globalCity1 = Cities->sRootName; globalLat1 = Cities->sLatitude; globalLon1 = Cities->sLongitude; } while(hasbeenfound == false); //while the entered city hasn't been found, repeat the process }else { bool hasbeenfound = false; do{ //ask the user to enter their second city of their choice whatever = "second "; cout << endl; cout << "Enter your " + whatever + "City" << endl; cout << "-------------------" << endl; cin >> userResponse; cout << endl; if (Cities->search(userResponse)) //check if the entered city already exist { hasbeenfound = true; } else{ cout << "City not Found" << endl; } //globalCity2 = Cities->sRootName; globalLat2 = Cities->sLatitude; globalLon2 = Cities->sLongitude; } while(hasbeenfound == false); //while the entered city hasn't been found, repeat the process } } // This function converts decimal degrees to radians double deg2rad(double deg) { return (deg * pi / 180); }; // This function converts radians to decimal degrees double rad2deg(double rad) { return (rad * 180 / pi); }; //distance calculations cout << endl; distan = sin(globalLat1)) * sin(deg2rad(globalLat2)) + cos(deg2rad(globalLat1)) * cos(deg2rad(globalLat2)) * cos(globalLon2 - globalLon1); distan = rad2deg(distan); distan = distan * 60 * 1.1515; distan = (6371 * pi * distan)/180; cout << "The Distance between the to cities is: " << distan << " kilometers" << endl; </code>