I'm new in C, hence, I am not sure where did I do wrong in the code. Could anyone help me out? I have tried compiling and running it. It shows perfectly until my second scanf, I've tried entering Y and N. Both will bring me to the below else condition.[This is one of the outcomes when I enter Y][1] Anyways is there a better way to code this program?
int main ()
{
float totalexp;
char paymentmethod, eligible, purchasepnp, purchaseadd;
int stamp=0;
do
{
printf("Enter your total expenses >>> ");
scanf( "%f",&totalexp);
printf("\n Payment using any of the below method? \n - AEON Member Plus Visa Card \n - AEON Credit Card \n - AEON Wallet \n (Y/N) \n");
scanf("% c", &paymentmethod); //Either Y or N, it'll just print both else {}
if (paymentmethod=='N')
{
stamp = totalexp / 30;
printf("You have gotten yourself %d stamps", stamp);
if (stamp>=20)
{
eligible = '1';
}
}
else if (paymentmethod=='Y')
{
stamp = (totalexp / 30)*3 ;
printf("You have gotten yourself %d stamps", stamp);
if (stamp>=15)
{
eligible = '1';
}
}
else
{
printf("\n Sorry, that is not an answer.");
}
if (eligible == '1')
{
printf("You are eligible in the P&P Tupperware products Redemptions!!");
printf("There are: \n (A)- Cherio Quad (1 Litre) \n %d stamps + RM10.90\n");
printf(" (B)- Large Square Round (2 Litre) \n %d stamps + RM18.90\n",stamp);
printf(" (C)- Reheatable Divided Lunch Box (1 Litre) \n %d stamps + RM33.90\n");
printf("Please choose A/B/C to make your purchase and T to terminate this purchase.\n");
scanf("% c", &purchasepnp);
if (purchasepnp=='A')
{
printf("Thank you for the purchase, \nTotal RM10.90, \n20 Stamps will be deducted.\n");
}
else if (purchasepnp=='B')
{
printf("Thank you for the purchase,\nTotal RM18.90, \n20 Stamps will be deducted.\n");
}
else if (purchasepnp=='C')
{
printf("Thank you for the purchase,\nTotal RM33.90, \n20 Stamps will be deducted.\n");
}
stamp -= 20;
printf("Your current stamps is: %d", stamp);
printf("Do you want to purchase more? (Y/N), or terminate this program (T)");
scanf("% c", &purchaseadd);
}
else
{
printf("You have insufficient stamps. \n Do you want to purchase more? (Y/N), or terminate this program (T) \n");
scanf("% c", &purchaseadd);
}
fflush (stdin);
}
while (purchaseadd=='Y'||purchaseadd=='y');
return 0;
} ```
[1]: https://i.stack.imgur.com/KVF3R.png