-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBILLING SYSTEM
173 lines (149 loc) · 4.46 KB
/
BILLING SYSTEM
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Define structures to represent customer and product
struct Customer {
int id;
char name[50];
};
struct Product {
int id;
char name[50];
float price;
};
// Define structures to represent a line item in an invoice
struct InvoiceItem {
struct Product product;
int quantity;
};
// Define a structure for an invoice
struct Invoice {
struct Customer customer;
struct InvoiceItem items[10]; // Assume a maximum of 10 items per invoice
int itemCount;
};
// Function prototypes
void displayMenu();
void addCustomer();
void addProduct();
void generateInvoice();
// Global arrays to store customers and products
struct Customer customers[10];
struct Product products[10];
int customerCount = 0;
int productCount = 0;
int main() {
int choice;
do {
displayMenu();
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addCustomer();
break;
case 2:
addProduct();
break;
case 3:
generateInvoice();
break;
case 4:
printf("Exiting the billing system. Goodbye!\n");
break;
default:
printf("Invalid choice. Please enter a valid option.\n");
}
} while (choice != 4);
return 0;
}
void displayMenu() {
printf("\n=== Billing System Menu ===\n");
printf("1. Add Customer\n");
printf("2. Add Product\n");
printf("3. Generate Invoice\n");
printf("4. Exit\n");
}
void addCustomer() {
if (customerCount < 10) {
printf("Enter customer name: ");
scanf("%s", customers[customerCount].name);
customers[customerCount].id = customerCount + 1;
customerCount++;
printf("Customer added successfully.\n");
} else {
printf("Maximum number of customers reached.\n");
}
}
void addProduct() {
if (productCount < 10) {
printf("Enter product name: ");
scanf("%s", products[productCount].name);
printf("Enter product price: ");
scanf("%f", &products[productCount].price);
products[productCount].id = productCount + 1;
productCount++;
printf("Product added successfully.\n");
} else {
printf("Maximum number of products reached.\n");
}
}
void generateInvoice() {
struct Invoice invoice;
int customerId, productId, quantity;
printf("Enter customer ID: ");
scanf("%d", &customerId);
// Find customer by ID
int customerIndex = -1;
for (int i = 0; i < customerCount; i++) {
if (customers[i].id == customerId) {
customerIndex = i;
break;
}
}
if (customerIndex == -1) {
printf("Customer not found.\n");
return;
}
// Set customer for the invoice
invoice.customer = customers[customerIndex];
invoice.itemCount = 0;
// Add products to the invoice
do {
printf("Enter product ID (0 to finish): ");
scanf("%d", &productId);
if (productId != 0) {
// Find product by ID
int productIndex = -1;
for (int i = 0; i < productCount; i++) {
if (products[i].id == productId) {
productIndex = i;
break;
}
}
if (productIndex != -1) {
// Set product and quantity for the invoice item
invoice.items[invoice.itemCount].product = products[productIndex];
printf("Enter quantity: ");
scanf("%d", &quantity);
invoice.items[invoice.itemCount].quantity = quantity;
invoice.itemCount++;
} else {
printf("Product not found.\n");
}
}
} while (productId != 0);
// Display the generated invoice
printf("\n=== Invoice ===\n");
printf("Customer: %s\n", invoice.customer.name);
printf("------------------------------\n");
printf("Product\t\tQuantity\tPrice\n");
float totalAmount = 0;
for (int i = 0; i < invoice.itemCount; i++) {
struct InvoiceItem item = invoice.items[i];
printf("%s\t\t%d\t\t%.2f\n", item.product.name, item.quantity, item.product.price);
totalAmount += item.quantity * item.product.price;
}
printf("------------------------------\n");
printf("Total Amount: %.2f\n", totalAmount);
}