-4

So, I am having some issues.

Create a project that looks up the driving distance between two cities. Use two drop-down lists that contain the names of the cities. Label one list Departure and the other Destination. Use a Look Up button to calculate the distance.

int[,] miles =
{
    {0, 1004, 1753, 2752, 3017, 1520, 1507, 609, 3115, 448},
    {1004, 0, 921, 1780, 2048, 1397, 919, 515, 2176, 709},
    {1753, 921, 0, 1230, 1399, 1343, 517, 1435, 2234, 1307},
    {2752, 1780, 1230, 0, 272, 2570, 1732, 2251, 1322, 2420},
    {3017, 2048, 1399, 272, 0, 2716, 1858, 2523, 1278, 2646},
    {1520, 1397, 1343, 2570, 2716, 0, 860, 1494, 3447, 1057},
    {1507, 919, 517, 1732, 1858, 860, 0, 1307, 2734, 1099},
    {609, 515, 1435, 2251, 2523, 1494, 1307, 0, 2820, 571},
    {3155, 2176, 2234, 1322, 1278, 3447, 2734, 2820, 0, 2887},
    {448, 709, 1307, 2420, 2646, 1057, 1099, 571, 2887, 0}
};

combo txtDeparture has been filled with the list of cities through the items property

combo txtDestination has been filled with the list of cities through the items property

Rufus L
  • 36,127
  • 5
  • 30
  • 43
Super_Fly
  • 115
  • 9
  • 1
    What kind of combo box? Web? Xarmin? Winforms? WPF? – Erik Philips Oct 24 '18 at 21:57
  • 1
    it is a windform combo box – Super_Fly Oct 24 '18 at 21:58
  • Well... how could we know? Use proper classes instead of an `int[,]` – Camilo Terevinto Oct 24 '18 at 22:04
  • 1
    You realize you've provide almost no information for anyone to help. We have no idea what *link up the array to combo box* means. Please take some time and completely read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask). – Erik Philips Oct 24 '18 at 22:04
  • Are your comboxes a list of 10 cities and the two dimensional array the distances between the cities? – Kevin Oct 24 '18 at 22:05
  • Why would users get to choose the miles between two cities? You don't want a ComboBox for that. – LarsTech Oct 24 '18 at 22:08
  • Would [ComboBox adding Text and Value](https://stackoverflow.com/questions/3063320/) help? – Dour High Arch Oct 24 '18 at 22:08
  • Yea that is it. I am not sure if I should if statement for every row and column – Super_Fly Oct 24 '18 at 22:09
  • Short of making a actually pathfinding algorythm (wich requires a tree structure to work on), the way would be to have a constant/runtime constant for every city. And use those as indexes. Enums and string[] would both work. The enum value or index value of each city would be used as a index in the "distances" array. And hte comboBoxes would allow selecting the city and the city ID as value. Personally I dislike this style of Multidimensional arrays and prefer using a jagged array. But whatever works fo you is okay in this case. – Christopher Oct 24 '18 at 23:08

1 Answers1

2

If the item in the comboboxes correspond to the 2D array you would want to do something like this:

var distance = miles[combotxtDeparture.SelectedIndex, combotxtDestination.SelectedIndex];
Kevin
  • 2,566
  • 1
  • 11
  • 12