Question

I'm working on my very 1st assignment and i just don't get it where i got my program wrong.I wrote the following program and when it comes to the last part,it's confusing.When the output is n,the program ends but when the input is y,it does not loop back into the switch part.Anyone??


int h,m;
float charge;
char a,d;

while (d!='n')
{
printf("B for Bus\n");
printf("C for Car\n");
printf("Vehicle type:");
scanf("%c",&a);

switch (a)
{
case 'B':
do
{ printf("Parking duration <hour>:");
scanf("%d",&h);
}while (h<0);

do
{ printf("Parking duration <minute>:");
scanf("%d",&m);
}while (m<0 || m>59);
printf("\n");

charge=3.00+(h-1)*1.50;
if (h==0 && m<60 && m>0)
printf("Charge: RM3.00\n");
else if (h==1 && m==0)
printf("Charge: RM3.00\n");
else if (h>1 && m==0)
printf("Charge: RM%.2f\n",charge);
else if (h>=1 && m<60 && m>0)
printf("Charge: RM%.2f\n",charge);
else
printf("Charge: RM0.00\n");


break ;






case 'C':

do
{printf("Parking duration <hour>:");
scanf("%d",&h);
} while (h<0);

do
{printf("Parking duration <minute>:");
scanf("%d",&m);
}while (m<0 || m>59);
printf("\n");

charge=3.00+(h-1)*1.00;
if (h==0 && m<60 && m>0)
printf("Charge: RM2.00\n");
else if (h==1 && m==0)
printf("Charge: RM2.00\n");
else if (h>1 && m==0)
printf("Charge: RM%.2f\n",charge);
else if (h>=1 && m<60 && m>0)
printf("Charge: RM%.2f\n",charge);
else
printf("Charge: RM0.00\n");
break;

default:
printf("\n");
break;
}
printf("Any more vehicle? [y/n]:");
scanf(" %c",&d);


}
Topic archived. No new replies allowed.