I want to count the months from Feb to Jan or Dec to July, how can I traverse repeatedly the array to get the counted months from Feb to Jan or Dec to July.
char * months[] = {"Jan", "Feb", "Mar", "April", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
char start_m[5];
char end_m[5];
float bill, rate;
float total;
scanf("%s %s %f %f",start_m, end_m,&bill, &rate);
int i, start, end;
for(i = 0; i < 12; i++){
if(strcmp(months[i], start_m) == 0){
start = i;
}
if(strcmp(months[i], end_m) == 0){
end = i;
}
}
if(end < start) {
for(i = start; i < start - end; i++){
total += (bill * rate);
}
} else {
for(i = start; i < end; i++){
total += (bill * rate);
}
}
total += bill;
printf("%.2f", total);