Below, is my prog. i know how to end loop with numbers and it gives me the correct value. I just learned how to end loop with 'q', though the value is not what i expected, the value got doubled!!! So someone plz tell me where im wrong. I still want it to end loop with 'q' and with right value also. I pretty much prefer if you just fix my program lines and with explanation so that i can understand better that way. Thx.
#include<stdio.h>
int main()
{
int Quantity[10], Product_No;
float Price = 0, Total = 0, Tax_Price = 0;
scanf("%d", &Product_No);
while ( 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("\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);
printf("How many orders of item number %d would you like? ", Product_No);
scanf("%d", &Quantity[Product_No - 1]);
if ( Product_No == 1)
{
Total += Quantity[0] * 47.90;
}
else if ( Product_No == 2)
{
Total += Quantity[1] * 28.90;
}
else if ( Product_No == 3)
{
Total += Quantity[2] * 17.90;
}
else if ( Product_No == 4)
{
Total += Quantity[3] * 19.90;
}
else if ( Product_No == 5)
{
Total += Quantity[4] * 39.50;
}
else if ( Product_No == 6)
{
Total += Quantity[5] * 34.90;
}
else if ( Product_No == 7)
{
Total += Quantity[6] * 19.90;
}
else if ( Product_No == 8)
{
Total += Quantity[7] * 25.90;
}
else if ( Product_No == 9)
{
Total += Quantity[8] * 29.90;
}
else if ( Product_No == 10)
{
Total += Quantity[9] * 19.90;
}
}
Price += Total;
printf("\n\n Please pay RM %.2f\n", Tax_Price = Price * 1.05);
printf("Thank you. Please come again!!");
return 0;
}