The double distance[MAX_CITIES][MAX_CITIES]
array is being allocated on the stack, and is causing your program to crash when something access the memory in the function.
This doesn't happen for the one outside the function because the compiler/linker allocates that block in the heap.
The solution is to dynamically allocate the memory (easiest is a single block):
double *distance = new double[MAX_CITIES*MAX_CITIES];
some_value = distance[(i*MAX_CITIES)+j];
delete[] distance;
Of course, this could still fail if MAX_CITIES is large, so then handle the failure gracefully.