-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCafe_Billing_System.c
More file actions
249 lines (208 loc) · 6.21 KB
/
Copy pathCafe_Billing_System.c
File metadata and controls
249 lines (208 loc) · 6.21 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define MAX 8
struct Product {
int id;
char name[30];
float price;
int quantity;
};
struct Product inventory[MAX] = {
{1, "Coffee", 40.0, 100},
{2, "Tea", 20.0, 120},
{3, "Burger", 120.0, 60},
{4, "Pizza", 250.0, 40},
{5, "Sandwich", 90.0, 80},
{6, "Fries", 110.0, 70},
{7, "ColdDrink", 60.0, 100},
{8, "IceCream", 80.0, 90}
};
struct Product cart[MAX];
int cartCount = 0;
void showMenu();
void showInventory();
void addToCart();
void showCart();
void removeFromCart();
void searchProduct();
void checkout();
int main() {
int option;
while(1) {
showMenu();
printf("\nEnter option: ");
scanf("%d", &option);
switch(option) {
case 1:
showInventory();
break;
case 2:
addToCart();
break;
case 3:
showCart();
break;
case 4:
removeFromCart();
break;
case 5:
searchProduct();
break;
case 6:
checkout();
break;
case 7:
printf("\nThank you. Visit again!\n");
return 0;
default:
printf("\nInvalid option. Please try again.\n");
}
}
}
void showMenu() {
printf("\n====== CAFE BILLING SYSTEM ======\n");
printf("1. Show Menu & Stock\n");
printf("2. Add Item to Cart\n");
printf("3. Show Cart\n");
printf("4. Remove Item from Cart\n");
printf("5. Search Product\n");
printf("6. Checkout & Print Bill\n");
printf("7. Exit\n");
printf("=================================\n");
}
void showInventory() {
printf("\n------------------ CAFE MENU ------------------\n");
printf("ID\tNAME\t\tPRICE\t\tSTOCK\n");
printf("-----------------------------------------------\n");
for(int i = 0; i < MAX; i++) {
printf("%d\t%-12s\tRs. %.2f\t%d\n",
inventory[i].id,
inventory[i].name,
inventory[i].price,
inventory[i].quantity);
}
printf("-----------------------------------------------\n");
}
void addToCart() {
int id, qty;
if(cartCount >= MAX) {
printf("\nCart is full!\n");
return;
}
printf("Enter product ID: ");
scanf("%d", &id);
for(int i = 0; i < MAX; i++) {
if(inventory[i].id == id) {
printf("Enter quantity: ");
scanf("%d", &qty);
if(qty > inventory[i].quantity) {
printf("\nNot enough stock available! Only %d left.\n", inventory[i].quantity);
return;
}
cart[cartCount] = inventory[i];
cart[cartCount].quantity = qty;
inventory[i].quantity -= qty;
cartCount++;
printf("\nItem added to cart successfully!\n");
return;
}
}
printf("\nProduct ID not found!\n");
}
void showCart() {
if(cartCount == 0) {
printf("\nCart is empty!\n");
return;
}
printf("\n------------------ YOUR CART ------------------\n");
printf("ID\tNAME\t\tPRICE\t\tQTY\n");
printf("-----------------------------------------------\n");
for(int i = 0; i < cartCount; i++) {
printf("%d\t%-12s\tRs. %.2f\t%d\n",
cart[i].id,
cart[i].name,
cart[i].price,
cart[i].quantity);
}
printf("-----------------------------------------------\n");
}
void removeFromCart() {
int id;
if(cartCount == 0) {
printf("\nCart is already empty!\n");
return;
}
printf("Enter product ID to remove: ");
scanf("%d", &id);
for(int i = 0; i < cartCount; i++) {
if(cart[i].id == id) {
for(int k = 0; k < MAX; k++) {
if(inventory[k].id == id) {
inventory[k].quantity += cart[i].quantity;
break;
}
}
for(int j = i; j < cartCount - 1; j++) {
cart[j] = cart[j + 1];
}
cartCount--;
printf("\nItem removed from cart and stock restored!\n");
return;
}
}
printf("\nItem not found in cart!\n");
}
void searchProduct() {
char name[30];
printf("Enter product name to search: ");
scanf("%s", name);
for(int i = 0; i < MAX; i++) {
if(strcasecmp(inventory[i].name, name) == 0) {
printf("\n--- Product Found ---\n");
printf("ID: %d\nName: %s\nPrice: Rs. %.2f\nStock Available: %d\n",
inventory[i].id,
inventory[i].name,
inventory[i].price,
inventory[i].quantity);
return;
}
}
printf("\nProduct not found!\n");
}
void checkout() {
float subtotal = 0;
if(cartCount == 0) {
printf("\nCannot checkout. Cart is empty!\n");
return;
}
srand(time(0));
int billNo = rand() % 10000 + 1000;
printf("\n==================== CAFE RECEIPT ====================\n");
printf("Bill No: %d\n", billNo);
printf("------------------------------------------------------\n");
printf("ID\tNAME\t\tPRICE\t\tQTY\tTOTAL\n");
printf("------------------------------------------------------\n");
for(int i = 0; i < cartCount; i++) {
float total = cart[i].price * cart[i].quantity;
printf("%d\t%-12s\tRs. %.2f\t%d\tRs. %.2f\n",
cart[i].id,
cart[i].name,
cart[i].price,
cart[i].quantity,
total);
subtotal += total;
}
float gst = subtotal * 0.05;
float finalAmount = subtotal + gst;
printf("------------------------------------------------------\n");
printf("Subtotal:\t\t\t\tRs. %.2f\n", subtotal);
printf("GST (5%%):\t\t\t\tRs. %.2f\n", gst);
printf("------------------------------------------------------\n");
printf("FINAL AMOUNT TO PAY:\t\t\tRs. %.2f\n", finalAmount);
printf("======================================================\n");
printf(" Thank you for visiting our cafe! \n");
printf("======================================================\n\n");
cartCount = 0;
}