Question: int congestedCity() { double tmp = 0.0; int tmpIdx = 0; double total = 0.0; for(int i=0; i
int congestedCity() {
double tmp = 0.0;
int tmpIdx = 0;
double total = 0.0;
for(int i=0; i for(int j=0; j<5; j++) { int x = getClosestCity(i); //this function gets the closest city total += getDistance(j, x); //this function gets the distance between cities. } if (total < tmp ) { tmp = total; tmpIdx = i; } return tmpIdx; } The problem I am having is I need to get the distance of the 5 closest cities to EACH city on the list of california cities. And then find the city with the SMALLEST total 5 distances. Which will give the most congested city in California... the function only gets the 5 distances for the first city on the list, it does not go through the entire list. What am I doing wrong?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
