Adak - The Yes No at the start is to ask and check whether there is any customer at that time. Thank you Adak for helping me out!
This is the latest code i've been working on. Everything looks ok, but if the user enter name that have 2 or more such as - Jackie Chan or Edward Scissor Hands , the Weight per [KG] will be skip.
No problem for single name such as Jack, Donald, Fatimah.
How can i fix this?
thank you
Code:
#include<stdio.h>
#include<string.h>
void main()
{
char customer_name[30], y, n, choice;
float weight, price, payment, total=0;
int customer=0;
printf("\n******************************************");
printf("\n** WELCOME TO GROCERIES SHOP **");
printf("\n******************************************");
printf("\nWould you like to continue? [Y/N]: ");
scanf("%c",&choice);
while(choice=='y' || choice=='Y')
{
printf("\nEnter customer name : ");
scanf("%s",&customer_name);
printf("\nEnter weight [KG] : ");
scanf("%f",&weight);
printf("\n------------------------------------------");
printf("\n- BILLING RECEIPT -");
printf("\n------------------------------------------");
printf("\nCustomer name : %s ",&customer_name);
printf("\nLaundy weight [KG] : %.2f",weight);
//nested if
if (weight<=3.0)
{
printf("\nPrice per [KG] :$ 1.20");
price=1.20;
}
else if (weight>3.0 && weight<6.0)
{
printf("\nPrice per [KG] :$ 1.00");
price=1.00;
}
else
{
printf("\nPrice per [KG] :$ 0.80");
price=0.80;
}
payment = price*weight;
total = total + payment;
printf("\nPayment :$ %.2f ",total);
fflush(stdin);
printf("\nWould you like to continue [Y/N] : ");
scanf("%c",&choice);
customer++;
}
printf("\n------------------------------------------");
printf("\n- TODAY'S SUMMARY -");
printf("\n------------------------------------------");
printf("\nTotal Payment :$ %.2f " ,total);
printf("\nTotal Customer : %d " ,customer);
printf("\n------------------------------------------");
printf("\n- THANK YOU -");
printf("\n------------------------------------------");
getch();
}