Code:
#include <stdio.h>
int main() {
char *stations[10]={"Ashford","Brentworth","Canonbury Cross","Dowgate","Edbury","Fenchurch Street","Gresham","Hampstead","Islington","Jamaica Road"};
int continueFlag=1;
int canDo =1;
char* dStation = malloc(sizeof(char));
char* aStation =malloc(sizeof(char));
int journey =1;
int price =0;
printf("********************************************************************************\n");
printf("*Usage:Input departure station name,arrival station name,single or return journey.\n");
printf("*Each station name is its first letter, 0 for single journey,1 for return journy. \n");
printf("*Example: A single ticket from Ashford to Edbury,the user can input ae0 or AE0 \n");
printf("*Press quit to close program \n");
printf("*Stations :{Ashford、Brentworth、Canonbury Cross、Dowgate、Edbury、 \n");
printf("* Fenchurch Street、Gresham、Hampstead、Islington、Jamaica Road} \n");
printf("******************************************************************************** \n");
while (continueFlag) {
fflush(stdin);
int retVal = scanf("%c%c%d",dStation,aStation,&journey);
if (retVal==3) {
if (isStationExist(*dStation)==0){
canDo=0;
printf("%c is not right station name \n",*dStation);
}
if (isStationExist(*aStation)==0) {
canDo=0;
printf("%c is not right station name \n",*aStation);
}
if (isTicketType(journey)==-1) {
canDo=0;
printf("%d is not right ticket type. 0 for single 1 for return\n",journey);
}
int startIndex = getStationIndex(dStation);
int endIndex = getStationIndex(aStation);
if(canDo) {
if (journey) {
price = abs(endIndex-startIndex)*returnPrice;
} else {
price = abs(endIndex-startIndex)*singlePrice;
}
char* tickType[2]={"single","return"};
printf("the %s price of station between %s and %s is ♀%d \n",*(tickType+journey),*(stations+startIndex),*(stations+endIndex),price);
} else {
printf("error input,please try again \n");
canDo=1;
}
}
else {
if (*dStation=='q') {
continueFlag=0;
} else {
printf("error input,please try again \n");
}
}
}
free(aStation);
free(dStation);
return 0;
}
please someone help me with this