-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
295 lines (251 loc) · 8.27 KB
/
main.c
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct cartcalc
{
int totalCost;
int incartid[50];
int incartprice[50];
char incartname[50][30];
} cart0;
static int mark=0;
void productmenu()
{
printf("\nSelect an option from the menu : ");
printf("\n1. Laptops");
printf("\n2. Mobiles");
printf("\n3. Headphones");
printf("\n4. Computer Accessories");
printf("\n5. Mobile Accessories");
printf("\n6. To Open Cart");
printf("\n7. To Checkout and Exit");
}
void addtocart(int t, char nm[], int q)
{
cart0.incartid[mark] = t;
cart0.incartprice[mark] = q;
strcpy(cart0.incartname[mark], nm);
mark++;
}
void cart(char nm[])
{
printf("\n--------------------%s's CART-------------------", nm);
for(int i=0; i<mark; i++)
printf("\nId=%d %s-> %d", cart0.incartid[i], cart0.incartname[i], cart0.incartprice[i]);
printf("\n\nTotal Cost : %d\n", cart0.totalCost);
if(mark==0)
printf("\nCart is Empty!!\n\n");
}
void editcart(char nm[])
{
printf("\n--------------------%s's CART-------------------", nm);
for(int i=0; i<mark; i++)
printf("\nId=%d %s-> %d", cart0.incartid[i], cart0.incartname[i], cart0.incartprice[i]);
printf("\n\nTotal Cost : %d\n\n", cart0.totalCost);
int ch, ch2, test=-1;
if(mark==0)
printf("\nCart is Empty!!\n\n");
else
{
printf("To Remove Any Item From Cart Press 1");
printf("\nTo Close Cart Press 0");
printf("\nEnter your choice : ");
scanf("%d", &ch);
if(ch==1)
{
printf("\n\nTo Remove Any Item Enter Id of Item : ");
scanf("%d", &ch2);
for(int i=0; i<mark; i++)
if(ch2 == cart0.incartid[i])
test=i;
if(test != -1)
{
cart0.totalCost -= cart0.incartprice[test];
mark--;
printf("%s Removed Successfully!\n\n", cart0.incartname[test]);
for(int j=test; j<mark; j++)
{
cart0.incartid[j] = cart0.incartid[j+1];
cart0.incartprice[j] = cart0.incartprice[j+1];
strcpy(cart0.incartname[j], cart0.incartname[j+1]);
}
}
else
printf("\nNo item found!!\n\n");
}
}
}
void buylaptop()
{
char laptops[9][30] = {"Dell Inspiron 3000","HP Pavilion x360","Dell G5 SE",
"Asus TUF Gaming","Lenovo Legion","Acer Aspire 7","Acer Nitro 5",
"Apple Macbook Air","HP 15s"};
int priceLaptops[9] = {41900,68300,92900,64990,89890,49990,65990,122990,62500};
int id[9], checkid = -1, p;
printf("\n\n--------------------Laptops(->Price)-------------------");
for(int i=0; i<9; i++)
{
id[i] = i+1;
printf("\nId=%d %s -> %d", id[i], laptops[i], priceLaptops[i]);
}
printf("\n\nWhich laptop do you want to buy (Enter Id): ");
scanf("%d", &checkid);
for(p=0; p<9; p++)
if(id[p] == checkid)
break;
if(p<9)
{
printf("\n%s is added to cart!\n\n", laptops[p]);
cart0.totalCost += priceLaptops[p];
addtocart(id[p], laptops[p], priceLaptops[p]);
}
else
printf("\nNo item found!!\n\n");
}
void buymobile()
{
char mobiles[9][30] = {"MI Note 10T Pro","Realme X3 Superzoom","Motorola Edge",
"Asus Rog 3","Poco X2","Vivo V20","IPhone 12 Max Pro","Nokia 5.3",
"OnePlus Nord Pro 5G"};
int priceMobiles[9] = {49999,28999,64999,46999,16999,24990,119900,13999,29999};
int id[9], checkid = -1, p;
printf("\n\n--------------------Mobiles(->Price)-------------------");
for(int i=0; i<9; i++)
{
id[i] = i+10;
printf("\nId=%d %s -> %d", id[i], mobiles[i], priceMobiles[i]);
}
printf("\n\nWhich mobile do you want to buy (Enter Id): ");
scanf("%d", &checkid);
for(p=0; p<9; p++)
if(id[p] == checkid)
break;
if(p<9)
{
printf("\n%s is added to cart!\n\n", mobiles[p]);
cart0.totalCost += priceMobiles[p];
addtocart(id[p], mobiles[p], priceMobiles[p]);
}
else
printf("\nNo item found!!\n\n");
}
void buyheadphone()
{
char headphones[9][30] = {"Philips SHP1900","Sony MDR-7506","Sennheiser HD 180",
"Sony MDR-XB450AP","iBall EarWear Rock","Senheiser HD 206","Samson CH700",
"Samson SR850","Panasonic RP-HT16"};
int priceHeadphones[9] = {699,8790,2585,2250,887,999,1490,3735,3384};
int id[9], checkid = -1, p;
printf("\n\n--------------------Headphones(->Price)-------------------");
for(int i=0; i<9; i++)
{
id[i] = i+19;
printf("\nId=%d %s -> %d", id[i], headphones[i], priceHeadphones[i]);
}
printf("\n\nWhich headphone do you want to buy (Enter Id): ");
scanf("%d", &checkid);
for(p=0; p<9; p++)
if(id[p]==checkid)
break;
if(p<9)
{
printf("\n%s is added to cart!\n\n", headphones[p]);
cart0.totalCost += priceHeadphones[p];
addtocart(id[p], headphones[p], priceHeadphones[p]);
}
else
printf("\nNo item found!!\n\n");
}
void buycompaccessory()
{
char compaccs[9][30] = {"TP-Link Wifi Range Extender","Monitor Cable(DVI)","USB Hub QHL",
"Monitor Cable","Card Reader","Blue-tooth Vista Ready","Logitech M-171 Mouse",
"HP C2500 Keyboard and Mouse","1 TB Hard Disk"};
int priceCompaccs[9] = {1200,150,55,125,350,160,825,790,2000};
int id[9], checkid = -1, p;
printf("\n\n--------------------Computer Accessories(->Price)-------------------");
for(int i=0; i<9; i++)
{
id[i] = i+28;
printf("\nId=%d %s -> %d", id[i], compaccs[i], priceCompaccs[i]);
}
printf("\n\nWhich Computer Accessory do you want to buy (Enter Id): ");
scanf("%d", &checkid);
for(p=0; p<9; p++)
if(id[p] == checkid)
break;
if(p<9)
{
printf("\n%s is added to cart!\n\n", compaccs[p]);
cart0.totalCost += priceCompaccs[p];
addtocart(id[p], compaccs[p], priceCompaccs[p]);
}
else
printf("\nNo item found!!\n\n");
}
void buymobileaccessory()
{
char mobileaccs[9][30] = {"MI 3i 10000 mAh PowerBank","iBall 10000 mAh PowerBank",
"boAt USB cable","Backcover for Poco X2","Tempered Glass for Poco X2","Backcover for Vivo V20",
"Tempered Glass for Poco F1","Mi USB cable","Ambrane USB Cable"};
int priceMobileaccs[9] = {799,499,129,259,189,229,329,149,89};
int id[9], checkid = -1, p;
printf("\n\n--------------------Mobile Accessories(->Price)-------------------");
for(int i=0; i<9; i++)
{
id[i] = i+37;
printf("\nId=%d %s -> %d", id[i], mobileaccs[i], priceMobileaccs[i]);
}
printf("\n\nWhich Mobile Accessory do you want to buy (Enter Id): ");
scanf("%d", &checkid);
for(p=0; p<9; p++)
if(id[p] == checkid)
break;
if(p<9)
{
printf("\n%s is added to cart.\n\n", mobileaccs[p]);
cart0.totalCost += priceMobileaccs[p];
addtocart(id[p], mobileaccs[p], priceMobileaccs[p]);
}
else
printf("\nNo item found!!\n\n");
}
void main()
{
int choice;
char name[50];
printf("Please Enter Your Name : ");
gets(name);
printf("\n-----------------------------------------------------------");
printf("\n--------------------PRIME SHOPPING POINT-------------------");
printf("\n-----------------------------------------------------------\n");
printf("\nHello %s, Welcome to Prime Shopping Point.\n",name);
while(1)
{
productmenu();
printf("\nEnter Your Choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1: buylaptop();
break;
case 2: buymobile();
break;
case 3: buyheadphone();
break;
case 4: buycompaccessory();
break;
case 5: buymobileaccessory();
break;
case 6: editcart(name);
break;
case 7: cart(name);
printf("\n-----------Your Final Bill is %d.-----------\n", cart0.totalCost);
printf("Thanks %s for Choosing Us and Visit us again.\n\n", name);
exit(0);
break;
default:printf("\nENTER VALID CHOICE!!\n");
break;
}
}
}