here is the full code but still give me 0 as minimum??????
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,k;
int taxi_list[NROWS][NCOLS];
int taxistates[NROWS],xtaxi[NROWS],ytaxi[NROWS];
double d_available[NROWS],d_inuse[NROWS],d_oncall[NROWS];
double min_available,min_inuse,min_oncall;
double t_available,t_inuse,t_oncall;
// 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));
}
// pick the smallest distance from d-available[i], d-inuse[i] and d-oncall[i]
//divide the smallest distance by 20 to get t1 t2 t3
for( i = 0; d_available[i] == 0 && i < NROWS; ++i ) ;
if( i == NROWS ) {
puts( "No nonzero at all" );
/* error handling */
}
printf( "First nonzero element = d_available[%d]\n", i );
for( min_available = 1; i < NROWS; ++i ) {
if( d_available[i] != 0 )
++min_available;
}
printf( "min_available: %d\n", min_available );
}
plz ayone can help