I am trying to read an excel file that four columns and four rows. First is city. Second is country. Third is latitude. Fourth is longitude. I was able to finally read them correctly and store them into variables thanks to another post I had. Then, I had to calculate the distance between those latitudes and longitudes and two other ones. Now, I am trying to put the distances into an array, so that I can access whatever index I want outside of the loop. Here is what I have:
while (!inFile.eof()) {
getline(inFile, city, ',');
getline(inFile, country, ',');
getline(inFile, lat, ',');
inFile >> lon;
//Converts string latitude and longitude to int to be able to use later
double latitude;
istringstream convert(lat);
if (!(convert >> latitude)) {
latitude = 0;
}//else do nothing, initializing not needed
double longitude;
istringstream convert1(lon);
if (!(convert1 >> longitude)) {
longitude = 0;
}//else do nothing, initializing not needed
City d1;
distanceArray[i] = d1.greatCircleDistance(latitude, longitude, lat1, lon1);
//Display great distance for all cities
cout << "Great distance between " << city << " and random city is " << d1.greatCircleDistance(latitude, longitude, lat1, lon1) << endl;
i++;
}
cout << distanceArray[1] << endl;
I am trying to put the distance between lat1, lat 2 and longitude, latitude in distanceArray so that after the loop when I put cout << distanceArray[1]
, it gives me the second distance.
But when I compile it, it tells me h.exe has stopped working. Why? I am so confused.