Code:#include <stdio.h> #include <string.h> #define ROWS 10 #define COLS 10 #define PLACE 15 typedef struct { char placeName[PLACE]; int miles[10]; }distances; int menu(void); void calcDistance(distances []); void totalCost(distances []); void dispChart(distances []); void readFile(distances []); int main() { int choice; distances places[10]; readFile(places); choice=menu(); while(choice !=4) { switch(choice) { case 1:/*display distance*/ dispDistance(places); break; case 2:/*calculate cost of journey*/ journeyCost(places); break; case 3:/*display the chart*/ dispChart(places); break; default: puts("Please enter a valid number"); }/*end switch*/ choice=menu(); }/*end while*/ return 0; } int menu(void) { int menuChoice; puts("\n"); puts("Menu"); puts("1) Display distance between two places"); puts("2) Calculate the cost of a journey"); puts("3) Display the mileage chart"); puts("Please select your choice or enter 0 to quit:"); scanf("%d",&menuChoice); fflush(stdin); return menuChoice; }/*end menu*/ void calcDistance(distances places[]) { int loop; char start,end; printf("Enter the name of the starting location: "); scanf("%d",&start); printf("Enter the next location or exit to return to the main menu: "); scanf("%d",&end); do { if x[loop+1] !=-1 distances[row].miles[col] loop++ }/*end do*/ while loop<5; return; }/*end calcDistance*/ void totalCost(distances places[]) { /*not sure how to call dispDistance*/ int dist; float cost; if(dist <=100) { cost = dist * 0.4; } else if(dist >100) { cost =(100 * 0.4)+((dist-100)*0.3); } printf("Cost of the journey is: %f\n", cost); }/*end totalCost*/ void dispChart(distances places[]) { int row,col; puts("Mileage chart"); for(row=0;row<ROWS;row++) { puts("");/*New line before each row*/ printf("%s\t",places[row].placeName);/*offset by 1(so 1,2,3,4,5 instead of 0,1,2,3,4)*/ for(col=0;col<COLS;col++) { printf("%d\t",places[row].miles[col]); }/*end for*/ }/*end for*/ }/*end dispChart*/ void readFile(distances places[]) { int loop; int innLoop; FILE *fp; fp=fopen("distance_chart.txt","r"); if(fp==NULL) { puts("\nFile not opened"); }/*end if*/ else { puts("\nOutput....."); for(loop=0;loop<10;loop++) { fscanf(fp,"%s",places[loop].placeName); for(innLoop=0;innLoop<10;innLoop++) { fscanf(fp,"%d",&places[loop].miles[innLoop]); }/*end for*/ }/*end for*/ if(fclose(fp)!=0) { puts("\nError closing file"); }/*end if*/ }/*end else*/ }/*end readFromFile*/ int placeSearch (distances places[]) { char place[PLACE]; int loop; scanf("%s",place); for(loop=0;loop<10;loop++) { if(strcmp(place,places[loop].placeName)==0) { return loop; } } return -1; }/*end placeSearch*/
In calcDistance I can't get the program to display the distance between two places?? Any suggestions??