In my code the answer for total = 0 always. I don't know what's the problem in my code. Can anyone help me please to solve this problem.
I tried using 'if else' condition instead of 'switch'. However the problem doesn't solve.
I think the 'pkg' value does not assign for the variable. But what is the reason for that. As I know it I have used the 'scanf' function correctly.
#include<stdio.h>
int main(void)
{
int i = 1;
float km, amount, total = 0;
char next, loyal, pkg;
printf("Enter Loyalty (Y / N) ?");
scanf("%*c%c", &loyal);
do{
printf("Package No : ");
scanf("%c*c", &pkg);
printf("Total Distance : ");
scanf("%f", &km);
if(km <= 80) {
switch (pkg){
case 'A':
amount = 1500;
break;
case 'B':
amount = 10000;
break;
case 'C':
amount = 13000;
break;
case 'D':
amount = 12000;
break;
}
}
else {
switch (pkg) {
case 'A':
amount = 1500 + 150 * (km - 80);
break;
case 'B':
amount = 10000 + 150 * (km - 80);
break;
case 'C':
amount = 13000 + 150 * (km - 80);
break;
case 'D':
amount = 12000 + 150 * (km - 80);
break;
}
}
total = total + amount;
i++;
printf("\nDo you have more customers (Y / N): ");
scanf("%*c%c", &next);
printf("----------------------------------------------\n");
} while (next == 'Y' && i <= 3);
printf("\n\nPrice = %.2f", total);
return 0;
}