-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDepartment Store Management System Project.c
78 lines (66 loc) · 2.12 KB
/
Department Store Management System Project.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Product {
int id;
char name[100];
float price;
};
struct CartItem {
struct Product product;
int quantity;
};
struct ShoppingCart {
struct CartItem items[100];
int itemCount;
float totalAmount;
};
void initializeCart(struct ShoppingCart *cart) {
cart->itemCount = 0;
cart->totalAmount = 0;
}
void addToCart(struct ShoppingCart *cart, struct Product product, int quantity) {
cart->items[cart->itemCount].product = product;
cart->items[cart->itemCount].quantity = quantity;
cart->totalAmount += product.price * quantity;
cart->itemCount++;
}
void displayCart(struct ShoppingCart cart) {
printf("Cart Contents:\n");
for (int i = 0; i < cart.itemCount; i++) {
printf("%d. %s - $%.2f x %d\n", i + 1, cart.items[i].product.name,
cart.items[i].product.price, cart.items[i].quantity);
}
printf("Total Amount: $%.2f\n", cart.totalAmount);
}
int main() {
struct Product products[3];
products[0] = (struct Product){1, "Product 1", 10.99};
products[1] = (struct Product){2, "Product 2", 20.49};
products[2] = (struct Product){3, "Product 3", 5.75};
struct ShoppingCart cart;
initializeCart(&cart);
int choice;
do {
printf("\nAvailable Products:\n");
for (int i = 0; i < 3; i++) {
printf("%d. %s - $%.2f\n", products[i].id, products[i].name, products[i].price);
}
printf("4. Checkout\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
if (choice >= 1 && choice <= 3) {
int quantity;
printf("Enter quantity: ");
scanf("%d", &quantity);
addToCart(&cart, products[choice - 1], quantity);
} else if (choice == 4) {
displayCart(cart);
} else if (choice != 5) {
printf("Invalid choice. Please try again.\n");
}
} while (choice != 5);
printf("Thank you for shopping with us!\n");
return 0;
}