0% found this document useful (0 votes)
79 views18 pages

Algorithm Supermarket Billing System-2

The Supermarket Billing System is a software application designed to automate the billing process in retail supermarkets, featuring product management, customer interaction, cart management, and billing calculations. The system enhances customer experience by simplifying purchases and improving operational efficiency. It includes an algorithm and code implementation for managing products, customer details, and payment processing.

Uploaded by

nivas.salla1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views18 pages

Algorithm Supermarket Billing System-2

The Supermarket Billing System is a software application designed to automate the billing process in retail supermarkets, featuring product management, customer interaction, cart management, and billing calculations. The system enhances customer experience by simplifying purchases and improving operational efficiency. It includes an algorithm and code implementation for managing products, customer details, and payment processing.

Uploaded by

nivas.salla1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

INDEX:

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:

1. Product Management: It displays a catalog of available products, including details


such as product name, price, discount percentage, and GST rates.
2. Customer Interaction: The system allows users to input their personal details,
including name and contact number, to create a personalized shopping experience.
3. Product Search: Customers can search for products by their name, which makes
finding items easier and quicker.
4. Cart Management: Users can add products to the cart, specify quantities, and view
the cart contents in real-time. They can also remove or adjust quantities of selected
items.
5. Billing and Payment: The system calculates the total price of the items, applying
the respective discounts and taxes (GST). The total amount is rounded off to the
nearest integer. The user is prompted to enter the cash received and the system
calculates and displays the change to be returned.
6. User-Friendly Interface: The system offers a clear and easy-to-navigate menu that
ensures smooth interaction throughout the shopping and billing process.

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. Define the structure for Product to store:


a. name
b. price
c. discount
d. gst
2. Define the structure for CartItem to store:
a. productIndex
b. quantity
3. Create an array of Product to store the available products.
4. Create an array of CartItem to store items added to the cart.
5. Initialize variables:
a. cartSize = 0 (tracks the number of items in the cart)
b. totalAmount = 0
c. totalItems = 0

Step 2: Collect Customer Details

1. Prompt the user to enter:


a. customerName
b. customerContact

Step 3: Display Available Products

1. Print all the available products with their details (name, price, discount, GST).

Step 4: Take User Input for Actions

1. Loop until the user decides to finish the order:


a. Display options:
i. Enter product number to add to the cart.

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.

Step 5: Handle User Actions

1. If user enters a product number:


a. Check if the input is valid (1 to the total number of products).
b. Prompt for quantity.
c. Add the product and quantity to the cart.
2. If user enters 99:
a. Prompt for a search query.
b. Search for products matching the query (case-insensitive).
c. Display matching results.
3. If user enters 88:
a. Display the current cart items.
b. Prompt the user to select an item to remove or adjust quantity.
c. Update the cart accordingly.

Step 6: Calculate Total Amount

1. Loop through all items in the cart:


a. Calculate the total price for each item using:
i. discount
ii. GST
b. Add the amount to totalAmount.
2. Round the totalAmount to the nearest integer.

Step 7: Generate and Display the Bill

1. Print the customer details.


2. Print the details of items in the cart (name, quantity, individual price, total price).
3. Print the total number of items and the rounded total amount.

Step 8: Handle Payment

1. Prompt the user to enter cashReceived.


2. Validate if cashReceived is greater than or equal to totalAmount:

4
a. If insufficient, prompt again.
b. If sufficient, calculate the change and display it.

Step 9: Display Exit Message

1. Print a thank-you message.


2. End the program.

Flowchart

5
6
Code
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

#define MAX_ITEMS 10

// Structure to store product details


typedef struct {
char name[50];
float price;
float discount;
float gst; // GST percentage
} Product;

typedef struct {
int productIndex;
int quantity;
} CartItem;

// Function to calculate the total amount for a product


float calculateAmount(float price, int quantity, float discount, float gst) {
float discountedPrice = price * (1 - discount / 100);
float totalPrice = discountedPrice * quantity * (1 + gst / 100);
return totalPrice;
}

// Function to convert a string to lowercase (for case-insensitive search)


void toLowerCase(char str[]) {
for (int i = 0; str[i]; i++) {
str[i] = tolower(str[i]);
}

7
}

// Function to search for a product


void searchProduct(Product products[], int count) {
char searchQuery[50];
char productNameLower[50], searchQueryLower[50];
int found = 0;

printf("Enter the product name or part of the name to search: ");


getchar(); // Clear buffer
fgets(searchQuery, sizeof(searchQuery), stdin);
searchQuery[strcspn(searchQuery, "\n")] = 0; // Remove newline character
toLowerCase(searchQuery);

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");
}

// Function to remove an item from the cart


void removeItemFromCart(CartItem cart[], int *cartSize) {
int removeIndex, newQuantity;
if (*cartSize == 0) {
printf("Cart is empty. No items to remove.\n");
return;

8
}

printf("Current items in the cart:\n");


for (int i = 0; i < *cartSize; i++) {
printf("%d. Product Index: %d, Quantity: %d\n", i + 1, cart[i].productIndex + 1, cart[i].quantity);
}

printf("Enter the item number to remove or adjust: ");


scanf("%d", &removeIndex);

if (removeIndex < 1 || removeIndex > *cartSize) {


printf("Invalid item number.\n");
return;
}

removeIndex--; // Convert to zero-based index


printf("Enter new quantity (0 to remove completely): ");
scanf("%d", &newQuantity);

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];

// Collecting customer details


printf("Enter customer name: ");
getchar(); // Clear buffer
fgets(customerName, sizeof(customerName), stdin);
customerName[strcspn(customerName, "\n")] = 0; // Remove newline character

printf("Enter customer contact number: ");


fgets(customerContact, sizeof(customerContact), stdin);
customerContact[strcspn(customerContact, "\n")] = 0; // Remove newline character

// Displaying the header


printf("\t\tWelcome to MG Mart Billing System\n");
printf("----------------------------------------------------------------\n");
printf("Available Products:\n");
for (int i = 0; i < MAX_ITEMS; i++) {
printf("%d. %s - Rs. %.2f (Discount: %.1f%%, GST: %.1f%%)\n",
i + 1, products[i].name, products[i].price, products[i].discount, products[i].gst);
}
printf("----------------------------------------------------------------\n");

// 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;
}

printf("Enter quantity for %s: ", products[choice - 1].name);


scanf("%d", &quantity);

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);
}

// Calculating total amount


for (int i = 0; i < cartSize; i++) {
int index = cart[i].productIndex;
float amount = calculateAmount(products[index].price, cart[i].quantity,
products[index].discount, products[index].gst);
totalAmount += amount;
totalItems += cart[i].quantity;

11
}

// Rounding off the total amount


float roundedTotal = roundf(totalAmount);

// Displaying the bill


printf("----------------------------------------------------------------\n");
printf("Customer Name: %s\n", customerName);
printf("Customer Contact: %s\n", customerContact);
printf("----------------------------------------------------------------\n");
printf("Total items: %d\n", totalItems);
printf("Total amount (before rounding): Rs. %.2f\n", totalAmount);
printf("Total amount (after rounding): Rs. %.2f\n", roundedTotal);

// Handling payment
while (1) {
printf("Enter cash received: Rs. ");
scanf("%f", &cashReceived);

if (cashReceived < roundedTotal) {


printf("Insufficient cash. Please provide more money.\n");
} else {
change = cashReceived - roundedTotal;
printf("Change to be returned: Rs. %.2f\n", change);
break;
}
}

// 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

1.The C Programming Language. 2nd Edition


Brian W. Kernighan, Dennis M. Ritchie

17
2.C Programming Absolute Beginner's Guide
Greg M. Perry, Dean Miller

3., The Complete Reference


Herbert Schildt

4.C Programming: A Modern Approach


Kim N. King

5.C in a Nutshell
Peter Prinz, Tony Crawford

18

You might also like