First, you'd need a list of all those cities you had, the distances between them, a simple map data structure (also known as a graph) that you can use to traverse which cities are more-or-less directly connected to each other.
For information about the map data structure, see Wikipedia Graph (data structure)
Once you have the cities in the graph correctly, you can traverse between any two points using Dijkstra's algorithm
. If the order added is the order you want to visit them in, just run Dijkstra's algorithm multiple times between all the city pairs and sum up the mileage.