I am trying to have a file that reads in planet locations (completely fictional) and calculates the distance between them all with a roadTrip function. However, I am having trouble when it comes to three or more planets, and I suspect it is how I am using the variables. Galaxy[i][j] is just the distance between planet A and B laid out on an array (chart).
Thanks!
Here is the roadTrip function
int Graph::roadTrip(int input, int start)
{
int distance = 0; //distance between planets (light years)
distance = Galaxy[start][input];
return distance;
}
Here is the main function
int main(int argc, char* argv[])
{
int input = 0;
int totalDistance = 0;
int start = 0; //planet you choose to start from
Graph test(argv[1]);
test.printLocations();
cout << endl;
cout << "Enter the planets you want to travel to. -1 to end." << endl;
cout << "What planet do you want to begin at?" << endl;
cin >> start;
while(input != -1)
{
cout << "Next planet?" << endl;
cin >> input;
totalDistance = test.roadTrip(input, start) + totalDistance;
}
cout << "Distance is " << totalDistance << " light years.";
}

New Topic/Question
Reply



MultiQuote




|