0% found this document useful (0 votes)
8 views6 pages

C Program

The document is a C program for a Store Management System that allows users to add products, view products, and generate invoices. It defines structures for products and invoices, manages a list of products and invoices, and provides functions to handle user interactions. The program runs in a loop, offering a menu for the user to choose actions until they decide to exit.

Uploaded by

praveenasri616
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)
8 views6 pages

C Program

The document is a C program for a Store Management System that allows users to add products, view products, and generate invoices. It defines structures for products and invoices, manages a list of products and invoices, and provides functions to handle user interactions. The program runs in a loop, offering a menu for the user to choose actions until they decide to exit.

Uploaded by

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

#include <stdio.

h>

#include <string.h>

#define MAX_PRODUCTS 100

#define MAX_INVOICES 100

typedef struct {

int id;

char name[50];

float price;

int quantity;

} Product;

typedef struct {

int product_id;

int quantity;

} InvoiceItem;

typedef struct {

int invoice_id;

InvoiceItem items[MAX_PRODUCTS];

int item_count;

float total_amount;

} Invoice;

Product products[MAX_PRODUCTS];

Invoice invoices[MAX_INVOICES];

int product_count = 0, invoice_count = 0;

void addProduct() {
if (product_count >= MAX_PRODUCTS) {

printf("Product list is full!\n");

return;

Product p;

p.id = product_count + 1;

printf("Enter product name: ");

scanf("%s", p.name);

printf("Enter product price: ");

scanf("%f", &p.price);

printf("Enter product quantity: ");

scanf("%d", &p.quantity);

products[product_count] = p;

product_count++;

printf("Product added successfully!\n");

void viewProducts() {

if (product_count == 0) {

printf("No products available.\n");

return;

printf("ID\tName\tPrice\tQuantity\n");

for (int i = 0; i < product_count; i++) {

printf("%d\t%s\t%.2f\t%d\n", products[i].id, products[i].name, products[i].price,


products[i].quantity);
}

void generateInvoice() {

Invoice inv;

inv.invoice_id = invoice_count + 1;

inv.item_count = 0;

inv.total_amount = 0.0;

int product_id, quantity;

printf("Enter number of items in the invoice: ");

scanf("%d", &inv.item_count);

for (int i = 0; i < inv.item_count; i++) {

printf("Enter product ID: ");

scanf("%d", &product_id);

if (product_id <= 0 || product_id > product_count) {

printf("Invalid product ID!\n");

i--;

continue;

printf("Enter quantity: ");

scanf("%d", &quantity);

if (products[product_id - 1].quantity < quantity) {

printf("Not enough stock available for %s!\n", products[product_id - 1].name);


i--;

continue;

// Decrease stock

products[product_id - 1].quantity -= quantity;

// Add item to the invoice

inv.items[i].product_id = product_id;

inv.items[i].quantity = quantity;

inv.total_amount += products[product_id - 1].price * quantity;

// Store the invoice

invoices[invoice_count] = inv;

invoice_count++;

// Print the invoice

printf("\nInvoice ID: %d\n", inv.invoice_id);

printf("Item\tQuantity\tPrice\tTotal\n");

for (int i = 0; i < inv.item_count; i++) {

int pid = inv.items[i].product_id;

printf("%s\t%d\t\t%.2f\t%.2f\n", products[pid - 1].name, inv.items[i].quantity, products[pid -


1].price, products[pid - 1].price * inv.items[i].quantity);

printf("\nTotal Amount: %.2f\n", inv.total_amount);

int main() {
int choice;

while (1) {

printf("\nStore Management System\n");

printf("1. Add Product\n");

printf("2. View Products\n");

printf("3. Generate Invoice\n");

printf("4. Exit\n");

printf("Enter your choice: ");

scanf("%d", &choice);

switch (choice) {

case 1:

addProduct();

break;

case 2:

viewProducts();

break;

case 3:

generateInvoice();

break;

case 4:

printf("Exiting...\n");

return 0;

default:

printf("Invalid choice. Please try again.\n");

return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy