my code looks like this now
Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define NROWS 20
#define NCOLS 3
#define STATECOL 0
#define XCOL 1
#define YCOL 2
main()
{
FILE *inputdata;
int i,j,xc,yc,tc;
int taxi_list[NROWS][NCOLS];
int taxistates[NROWS],xtaxi[NROWS],ytaxi[NROWS];
double d_available[NROWS],d_inuse[NROWS],d_oncall[NROWS];
// customer info.
printf(" please note that u need to press enter after entering any inputs \n Enter your location as X and Y coordenate:\n");
printf("Enter your X-coordenate \n X=");
scanf("%d",&xc);
printf("Enter your Y-coordenate \n Y=");
scanf("%d",&yc);
printf("after how many mins you need the taxi ");
scanf("%d",&tc);
//open input file to read
inputdata=fopen("taxis_info.txt","r");
if (inputdata==NULL){
printf("error canot open taxis_info \n");
exit(1);
}
//read all info from input file to one array
for (i=0;i<NROWS;i++){
for(j=0;j<NCOLS;j++){
fscanf(inputdata,"%d",&taxi_list[i][j]);
}
}
// creat 3 different arrays from the previous 20x3 array
//for taxistates,x-coord, y-coord of the taxis
for ( i = 0 ; i < NROWS ; i++ ) {
taxistates[i] = taxi_list[i][STATECOL];
xtaxi[i] = taxi_list[i][XCOL];
ytaxi[i] = taxi_list[i][YCOL];
}
//craet 3 arrays to hold distance from customer to available,inuse and oncall taxis
//initialise the three arrays with zeros
for(i=0;i<NROWS;i++){
d_available[i]=0;
d_inuse[i]=0 ;
d_oncall[i]=0 ;
}
//check taxistates f (ie available,inuse,oncall or not available taxis)
//calculate distance between customer and each available,inuse and oncall taxi
//place each set of distances in an array
for (i=0;i<NROWS;i++){
if (taxistates[i]==1)
d_available[i]=sqrt(pow(xc-xtaxi[i],2)+pow(yc-ytaxi[i],2));
else if (taxistates[i]==2)
d_inuse[i]=sqrt(pow(xc-xtaxi[i],2)+pow(yc-ytaxi[i],2)) ;
else if (taxistates[i]==3)
d_oncall[i]=sqrt(pow(xc-xtaxi[i],2)+pow(yc-ytaxi[i],2));
}
//testing distance calcultaion
printf("%d",d_available[5]);
printf("\n");
}