Algorithm Supermarket Billing System-2
Algorithm Supermarket Billing System-2
1.Abstract pg: 1
2.Algorithm
pg:2-5
3.Flowchart pg:6
4.Code
pg:7-12
5.Results pg:13-16
6.References
pg:17
1
ABSTRACT
The Supermarket Billing System is a software application developed to automate the
billing process of a retail supermarket. This system allows customers to easily purchase
items, view product details, and generate bills with calculated discounts and taxes. The
program includes the following key features:
This system aims to enhance the customer experience by simplifying the purchase
process, reducing human error, and improving operational efficiency in retail stores. By
automating product selection, billing calculations, and payment handling, it provides a
convenient and accurate way for both customers and retailers to complete transactions.
2
Algorithm: Supermarket Billing System
Algorithm: Supermarket Billing System
Step 1: Initialization
1. Print all the available products with their details (name, price, discount, GST).
3
ii. Enter 99 to search for a product.
iii. Enter 88 to remove an item from the cart.
iv. Enter 0 to finish and proceed to billing.
4
a. If insufficient, prompt again.
b. If sufficient, calculate the change and display it.
Flowchart
5
6
Code
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define MAX_ITEMS 10
typedef struct {
int productIndex;
int quantity;
} CartItem;
7
}
printf("Search Results:\n");
printf("----------------------------------------------------------------\n");
for (int i = 0; i < count; i++) {
strcpy(productNameLower, products[i].name);
toLowerCase(productNameLower);
if (strstr(productNameLower, searchQuery) != NULL) {
printf("%d. %s - Rs. %.2f (Discount: %.1f%%, GST: %.1f%%)\n",
i + 1, products[i].name, products[i].price, products[i].discount, products[i].gst);
found = 1;
}
}
if (!found) {
printf("No products found matching '%s'.\n", searchQuery);
}
printf("----------------------------------------------------------------\n");
}
8
}
if (newQuantity == 0) {
// Remove item completely
for (int i = removeIndex; i < *cartSize - 1; i++) {
cart[i] = cart[i + 1];
}
(*cartSize)--;
printf("Item removed successfully.\n");
} else {
// Adjust quantity
cart[removeIndex].quantity = newQuantity;
printf("Item quantity updated successfully.\n");
}
}
int main() {
// List of available products
Product products[MAX_ITEMS] = {
{"Sunsilk Shampoo (375ml)", 290.00, 25, 5},
{"V-Three Casual Bagpack", 745.00, 50, 12},
9
{"Adidas Men's T-Shirt (Size L)", 275.00, 30, 5},
{"Cadbury Silk Chocolates (Pack of 10)", 800.00, 20, 18},
{"Chings Noodles (100 gm)", 10.00, 0, 5},
{"Tupperware Bottle (750 ml)", 999.00, 10, 18},
{"Sensodyne Toothpaste (75 ml)", 93.95, 2, 12},
{"Pepsodent Toothbrush", 17.00, 4, 5},
{"Nivia Tennis Ball (Pack of 12)", 810.00, 12, 18},
{"Sparx Training Shoes (Size 8/9/10)", 8000.00, 18, 28}
};
CartItem cart[MAX_ITEMS];
int cartSize = 0;
int choice, quantity, totalItems = 0;
float totalAmount = 0, cashReceived, change;
char customerName[50], customerContact[15];
// Taking orders
while (1) {
10
printf("Enter the product number (1-%d), 99 to search, 88 to remove item, or 0 to finish: ",
MAX_ITEMS);
scanf("%d", &choice);
if (choice == 0) {
break;
} else if (choice == 99) {
searchProduct(products, MAX_ITEMS);
continue;
} else if (choice == 88) {
removeItemFromCart(cart, &cartSize);
continue;
} else if (choice < 1 || choice > MAX_ITEMS) {
printf("Invalid choice. Please try again.\n");
continue;
}
if (quantity <= 0) {
printf("Invalid quantity. Please try again.\n");
continue;
}
cart[cartSize].productIndex = choice - 1;
cart[cartSize].quantity = quantity;
cartSize++;
printf("Added %d x %s to cart.\n", quantity, products[choice - 1].name);
}
11
}
// Handling payment
while (1) {
printf("Enter cash received: Rs. ");
scanf("%f", &cashReceived);
// Footer
printf("----------------------------------------------------------------\n");
printf("\t\tThank you for shopping at MG Mart!\n");
printf("\t\tVisit again!\n");
printf("----------------------------------------------------------------\n");
return 0;
}
12
Results Screeshots
13
1.
2.
After entering customer name and contact number
3.
14
Enter the product number (1-10), 99 to search, 88 to remove item, or o
to finish: 2
4.
15
Searching
5.
Removing items
6.
Finishing by entering 0
16
7.
Cash receiving
References
17
2.C Programming Absolute Beginner's Guide
Greg M. Perry, Dean Miller
5.C in a Nutshell
Peter Prinz, Tony Crawford
18