I understand that ending the loop for this menu, you have to type in 11. It works well w/ numbers to end loop. Though, what i am really after now, is i want to learn how to end the menu loop using 'q'. I have tried many ways, and so far I'm still unable to get it. I understand that, if you if you program like this ((Product_No=getchar())!= 81), that 81 is converted to q, in ascii form. But still i dont understand because even though i typed it out there, does not work. Anyone, plz help me here. Help me by fixing my program lines below to end menu loop with 'q' and also explain it so that i understand it. Thx.
#include<stdio.h>
int main()
{
int Quantity[10], Product_No;
float Price = 0, Total = 0, Tax_Price = 0;
while ((Product_No =getchar())!= 'q')
{
printf("\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@\n");
printf(" CareKidz \n");
printf(" Carrefour Subang Jaya \n");
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@\n");
printf("Welcome To CareKidz System!!\n");
printf("Make Your Selection from the menu below:\n\n");
printf("\t1. Pampers Baby Dry (Super Value Pack)\tRM 47.90\n");
printf("\t2. Sumo Confort Super Value\t\tRM 28.90\n");
printf("\t3. Pet-Pet Baby dry\t\t\tRM 17.90\n");
printf("\t4. Chicolastic Ultra trim Jumbo\t\tRM 19.90\n");
printf("\t5. Mamy Poko Disney\t\t\tRM 39.50\n");
printf("\t6. Drypers Wee-Wee Mega Pack\t\tRM 34.90\n");
printf("\t7. Royale Kids Grace Kiki Lala Shoes\tRM 19.90\n");
printf("\t8. OK Baby Wear\t\t\t\tRM 25.90\n");
printf("\t9. World Of Cartoon Kids Wear\t\tRM 29.90\n");
printf("\t10. Christmas Teddy Bear\t\tRM 19.90\n");
printf("\n\t11.\tExit System\n");
printf("\nType Q when you are finished with your selections.\n");
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@\n");
printf("Select 1,2,3,4,5,6,7,8,9 or 10--> ");
scanf("%d", &Product_No);
if ((Product_No=getchar()) != 'q')
{
printf("How many orders of item number %d would you like? ", Product_No);
scanf("%d", &Quantity[Product_No - 1]);
}
switch (Product_No)
{
case 1:
Total += Quantity[0] * 47.90; /****notice the += instead of =****/
break;
case 2:
Total += Quantity[1] * 28.90;
break;
case 3:
Total += Quantity[2] * 17.90;
break;
case 4:
Total += Quantity[3] * 19.90;
break;
case 5:
Total += Quantity[4] * 39.50;
break;
case 6:
Total += Quantity[5] * 34.90;
break;
case 7:
Total += Quantity[6] * 19.90;
break;
case 8:
Total += Quantity[7] * 25.90;
break;
case 9:
Total += Quantity[8] * 29.90;
break;
case 10:
Total += Quantity[9] * 19.90;
break;
case 11:
Price += Total;
printf("\n Please pay RM %.2f\n", Tax_Price = Price * 1.05);
printf("Thank you. Please come again!!");
return 0;
default:
printf("\nSorry, the Product No. you entered was not on the menu. Please try again!");
}
}
}