thanks again elad-
i already got it to work before yor post though...sort of.
I'm having trouble with my function that compares the inputted string (a city) to all the cities in the array. It is supposed to be a search function.
Code:
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdlib> //includes libraries
#include<string>
using namespace std;
const int SIZE= 25375;
string city[SIZE];
char letters[80];
double latitude[SIZE];
double longitude[SIZE];
int saveMe[1000];
int counter=0;
void calculateDistance(double startingLatitude, double endingLatitude, double startingLongitude,
double endingLongitude, double dist, int j)
{
const double Pi= 3.14159265359;
double radiusEarth=3958.8, distance;
startingLatitude= ((startingLatitude)/180)*Pi;
endingLatitude= ((endingLatitude)/180)*Pi;
startingLongitude= ((startingLongitude1)/180)*Pi;
endingLongitude= ((endingLongitude1)/180)*Pi;
distance = cos(startingLatitude)*cos(endingLatitude)*cos(startingLongitude-endingLongitude);
distance += (sin(startingLatitude)*sin(endingLatitude));
distance = acos(distance);
distance *= radiusEarth;
if(distance<=dist){
saveMe[counter]=j;
counter++;
}
}
int checkDistance(int position,double distance, int i)
{
do{
if(i != position)
calculateDistance(latitude[position], latitude[i], longitude[position], longitude[i], distance);
i++;
}while(i<25375);
return0;
}
int search()
{
string input;
int i= 0, pos=-1;
cin>>input;
do{
if (input.find(city[i]) != -1){
cout<<city[i]<<endl;
if (pos != -1)
return -2;
pos = i;}
i++;
}while(i<25375);
cout<<"hello "<<pos<<endl;
return pos;
}
int main()
{
ifstream inStream;
inStream.open("US-PLACES.txt");
int i= 0, pos;
string place;
double lat, longi, distanceLimit;
while(!inStream.fail())
{
inStream >> place >> lat >> longi;
city[i] = place;
latitude[i] = lat;
longitude[i] = longi;
i++;
}
cout<<"Thank you for calling information. What city please?"<<endl;
pos=search();
if (pos == -2){
cout<<"Narrow your search down!!"<<endl;
return(-1);
}
if (pos == -1){
cout<<"Nothing found!!"<<endl;
return(-1);
}
cout<<endl<<pos<<endl;
cout<<"What is your distance limit"<<endl;
cin>>distanceLimit;
checkDistance(pos,distanceLimit);
return(0);
}
the way i want the search function to work is that i want it to return -1 if no matches were found, return -2 if several matches were found, and return the position of the array if only one match was found. I appreciate your help.