If I read the question correctly, you need to store the location and type of a building in double arrays and char arrays. The logical approach would be to use the two double arrays for the coordinates and the char array for the type.
An example:
1 2 3
|
double xlocations[20]; //Array of twenty x-coordinates
double ylocations[20]; //Array of twenty y-coordinates
char types[20]; //Array of twenty types
|
The first thing you need to do is fill the arrays somehow, this shouldn't be too much of a problem. Using a simple for loop you should be able to figure this out yourself. Next thing to do would be to store the users location:
|
double userx, double usery;
|
Fill them from standard input like you filled up the locations, this shouldn't be a problem.
Next we need a formula for the distance. We're working in a 2D grid, so we can calculate the distance between two points using simple Pythagoras. The general formula is:
1 2
|
double distance = std::sqrt(std::pow(xlocation[i]-userx,2)
+ std::pow(ylocation[i]-usery,2));
|
This can be called in a for loop. If I read your question correctly, there are only 3 types of buildings: hospital, university and pharmacy. We'll each give these a number: hospital = 0, university = 1 and pharmacy = 2. We can then use a switch to determine the type:
1 2 3 4 5 6 7 8 9 10 11 12
|
switch(types[i])
{
case 0:
if(distance < hospitaldistance)
{
hospitaldistance = distance;
hospitalx = xlocations[i];
hospitaly = ylocations[i];
}
break;
//Etc for the other types
}
|
Then after the for loop, we should print the found result. I think you should now have an idea of how to implement such a program. Good luck with it.