0% found this document useful (0 votes)
7 views

afrinc

This document contains a C program for a Store and Invoice Management system that allows users to add, update, display, purchase, and check the availability of products. It defines a 'Product' structure and includes functions for managing product inventory. The program operates in a loop until the user chooses to exit, providing a menu-driven interface for interaction.

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)
7 views

afrinc

This document contains a C program for a Store and Invoice Management system that allows users to add, update, display, purchase, and check the availability of products. It defines a 'Product' structure and includes functions for managing product inventory. The program operates in a loop until the user chooses to exit, providing a menu-driven interface for interaction.

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>

struct Product

int productID;

char productName[50];

int quantity;

float unitPrice;

};

void addProduct(struct Product *products, int *productCount);

void updateProduct(struct Product *products, int productCount);

void displayProducts(const struct Product *products, int productCount);

void purchaseProduct(struct Product *products, int productCount);

void checkAvailability(const struct Product *products, int productCount);

#define MAX_PRODUCTS 100

int main() {

struct Product products[MAX_PRODUCTS];

int productCount = 0;

int choice;

do

printf("\n--- Store and Invoice Management ---\n");

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

printf("2. Update Product Details\n");


printf("3. Display Products\n");

printf("4. Purchase Product\n");

printf("5. Check Product Availability\n");

printf("6. Exit\n");

printf("Enter your choice: ");

scanf("%d", &choice);

switch (choice) {

case 1:

addProduct(products, &productCount);

break;

case 2:

updateProduct(products, productCount);

break;

case 3:

displayProducts(products, productCount);

break;

case 4:

purchaseProduct(products, productCount);

break;

case 5:

checkAvailability(products, productCount);

break;

case 6:

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

break;

default:

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

}
} while (choice != 6);

return 0;

void addProduct(struct Product *products, int *productCount)

if (*productCount >= MAX_PRODUCTS) {

printf("Inventory is full. Cannot add more products.\n");

return;

struct Product newProduct;

printf("Enter Product ID: ");

scanf("%d", &newProduct.productID);

printf("Enter Product Name: ");

scanf("%s", newProduct.productName);

printf("Enter Quantity: ");

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

printf("Enter Unit Price: ");

scanf("%f", &newProduct.unitPrice);

for (int i = 0; i < *productCount; i++) {

if (strcmp(products[i].productName, newProduct.productName) == 0) {

printf("Product already exists in the stock.\n");

return;

products[*productCount] = newProduct;
(*productCount)++;

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

void updateProduct(struct Product *products, int productCount)

int productID, found = 0;

printf("Enter Product ID to update: ");

scanf("%d", &productID);

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

if (products[i].productID == productID) {

printf("Enter new quantity: ");

scanf("%d", &products[i].quantity);

printf("Enter new unit price: ");

scanf("%f", &products[i].unitPrice);

printf("Product details updated successfully.\n");

found = 1;

break;

if (!found) {

printf("Product not found.\n");

void displayProducts(const struct Product *products, int productCount)

{
if (productCount == 0) {

printf("No products in the inventory.\n");

return;

printf("\n--- Product List ---\n");

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

printf("Product ID: %d\n", products[i].productID);

printf("Product Name: %s\n", products[i].productName);

printf("Quantity: %d\n", products[i].quantity);

printf("Unit Price: %.2f\n", products[i].unitPrice);

printf("-------------------------\n");

void purchaseProduct(struct Product *products, int productCount)

char productName[50];

int quantity;

printf("Enter Product Name to purchase: ");

scanf("%s", productName);

printf("Enter quantity: ");

scanf("%d", &quantity);

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

if (strcmp(products[i].productName, productName) == 0) {

if (products[i].quantity >= quantity) {

products[i].quantity -= quantity;
printf("Purchase successful. Total cost: %.2f\n", quantity * products[i].unitPrice);

} else {

printf("Insufficient stock. Available quantity: %d\n", products[i].quantity);

return;

printf("Product not found.\n");

void checkAvailability(const struct Product *products, int productCount) {

char productName[50];

printf("Enter Product Name to check availability: ");

scanf("%s", productName);

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

if (strcmp(products[i].productName, productName) == 0) {

printf("Product is available. Quantity: %d\n", products[i].quantity);

return;

printf("Product not available.\n");

You might also like