/* --------------------------------------------------------------------- ** Figure 17.7: Travel time for a 2-day trip. ** --------------------------------------------------------------------- */ #include "tools.h" #define NTOWNS 5 #define INFILE "minutes.in" void main( void ) { stream minutes; /* Data for travel-time matrix */ string towns[NTOWNS] = { "Albany","Boston","Buffalo","Hartford","New York" }; int timetable[NTOWNS][NTOWNS]; int row, col; int city1, city2, city3; /* Cities along rout of trip. */ int time; banner(); printf( "\n\n Travel Time \n\n" ); minutes = fopen( INFILE, "r" ); if (minutes == NULL) fatal( " Cannot open %s for reading.", INFILE ); for (row = 0; row < NTOWNS; ++row) /* Read travel-time matrix. */ for (col = 0; col < NTOWNS; ++col) { fscanf( minutes, "%i", &timetable[row][col] ); } city1 = menu_i( " Where will your trip start?", NTOWNS, towns ); city2 = menu_i( " Where will you stay overnight?", NTOWNS, towns ); city3 = menu_i( " What is your destination?", NTOWNS, towns ); time = timetable[city1][city2] + timetable[city2][city3]; printf( "\n Travel time from %s to %s to %s\n\t will be %i minutes.\n", towns[city1], towns[city2], towns[city3], time ); bye(); }