Repetition and Selection

For the "printf("Total for %d bills: RM%.2f\n",count,subtotal);" the subtotal would print out exactly the same like the 2nd bill of "printf("**Amount for bill #%d: %.2f\n",count,total);", if we were to put 2 bills at the beginning of the program, meanwhile the total would increase by 1, if we were to print it out. So, how do I fix this? Thank you in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

#include <stdio.h>
#define TAX 0.05
int main()
{
	int bill,item,count,quantity,code,counta;
	float price,total,subtotal,tax;
	char ans;
		
	printf("******** EmMar Trading *********\n");
	
	do
	{
		printf("\nHow many bills?:");
		scanf("%d",&bill);
		
		count=1; total=0;
		while(count<=bill)
		{
			printf("Bill #%d: \n",count);
			printf("No of items: ");
			scanf("%d",&item);	
		
			printf("\n------------------------------\n");
			
			counta=1;
			while(counta<=item)									
			{
				printf("Item #%d code: p",counta);
				scanf("%d",&code);
				printf("Quantity: ");
				scanf("%d",&quantity);
					{
		 				switch(code) 
					 		{ 	
							 	case 300: printf("%d x Mexican Dishes @ RM%.2f each\n",quantity,price=20); break;
					 			case 350: printf("%d x Asian Kitchen @ RM%.2f each\n",quantity,price=30); break;
								case 400: printf("%d x La Tahzan @ RM%.2f each\n",quantity,price=15); break;
								case 500: printf("%d x Java Programming @ RM%.2f each\n",quantity,price=30); break;
								case 600: printf("%d x Upin dan Ipin @ RM%.2f each\n",quantity,price=5); break;
							}
					}
				price=quantity*price;
				printf("Price (RM): %.2f\n",price);
				counta++;
				total+=price;
				printf("**Amount for bill #%d: %.2f\n",count,total);	
				}
			count++;
			printf("\n______________________________\n");
			printf("\n");
		}
		subtotal+=total;
		printf("Total for %d bills: RM%.2f\n",count,subtotal);
		tax=subtotal*TAX;
		printf("5%% tax: RM%.2f\n",tax);
		printf("Total Amount Due: RM%.2f\n",subtotal+tax);
		printf("\t\t  ========\n");
		
	printf("Do you want to continue? (Y/N): ");
	fflush(stdin);
    scanf("%c",&ans);
	}while(ans=='Y'||ans=='y');
	printf("Thank You.\n");
	
	system ("pause");
	return 0;
}
Topic archived. No new replies allowed.