Write a C Program to Maintain Inventory items in Online Store

By | 03.12.2016

C Program to Maintain Inventory items in Online Store


Write a C Program to Maintain Inventory items in Online Store. This C Program display the inventory of items in a store.

So what we doing in this c program is to accept the number of items from the user, then we make a for loop up to the number of items to add that number of products.

In this for loop what we doing is to accept the values for name, price, item quantity and date from the user for each product using the for loop we have started.

Finally we print the product details in the table format using for loop. we use a flush also to clear the memory, also we use a struct variable to store the details.


Below is the source code of the C program to Maintain Inventory items in Online Store which is successfully compiled and run on the windows system.The Output of the program is shown below.


SOURCE : :


/*
 * C program to display the inventory of items in a store / shop
 * The inventory maintains details such as name, price, quantity
 * and manufacturing date of each item.
 */

#include <stdio.h>
#include <conio.h>
void main() {
    struct date {
                int day;
                int month;
                int year;
        };
        struct details {
                char name[20];
                int price;
                int code;
                int qty;
                struct date mfg;
        };
        struct details item[50];
        int n,i;
        clrscr();
        printf("Enter number of items:");
        scanf("%d",&n);
        fflush(stdin);
        for (i=0;i<n;i++) {
                fflush(stdin);
                printf("Item name:");
                scanf("%[^\n]",item[i].name);
                fflush(stdin);
                printf("Item code:");
                scanf("%d",&item[i].code);
                fflush(stdin);
                printf("Quantity:");
                scanf("%d",&item[i].qty);
                fflush(stdin);
                printf("price:");
                scanf("%d",&item[i].price);
                fflush(stdin);
                printf("Manufacturing date(dd-mm-yyyy):");
                scanf("%d-%d-%d",&item[i].mfg.day,&item[i].mfg.month,&item[i].mfg.year);
        }
   printf("             *****  INVENTORY *****\n");
   printf("------------------------------------------------------------------\n");
   printf("S.N.|    NAME           |   CODE   |  QUANTITY |  PRICE  |MFG.DATE\n");
   printf("------------------------------------------------------------------\n");
   for (i=0;i<n;i++)
      printf("%d   %-15s   %-d  %-5d  %-5d %d/%d/%d\n",i+1,item[i].name,item[i].code,item[i].qty,item[i].price,item[i].mfg.day,item[i].mfg.month,item[i].mfg.year);
        printf("------------------------------------------------------------------\n");
        getch();
}

Also Read : : Write a C program to Perform Operator Precedence


OUTPUT : :


Enter number of items:5
Item name:Tea Powder
Item code:123
Quantity:23
price:40
Manufacturing date(dd-mm-yyyy):12-03-2009
Item name:Milk Powder
Item code:345
Quantity:20
price:80
Manufacturing date(dd-mm-yyyy):30-03-2009
Item name:Soap Powder
Item code:510
Quantity:10
price:30
Manufacturing date(dd-mm-yyyy):01-04-2009
Item name:Washing Soap
Item code:890
Quantity:25
price:12
Manufacturing date(dd-mm-yyyy):10-03-2009
Item name:Shampo
Item code:777
Quantity:8
price:50
Manufacturing date(dd-mm-yyyy):17-05-2009
                                 *****  INVENTORY *****
------------------------------------------------------------------------
S.N.|    NAME           |   CODE   |  QUANTITY |  PRICE  |MFG.DATE
------------------------------------------------------------------------
1     Tea Powder             123          23        40        12/3/2009
2     Milk Powder            345          20        80        30/3/2009
3     Soap Powder            510          10        30        1/4/2009
4     Washing Soap           890          25        12        10/3/2009
5     Shampo                 777          8         50        17/5/2009
-----------------------------------------------------------------------------
-----------------------------------------------------------------------*/
3.7 3 votes
Article Rating
Category: Advance Programs C Programming Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Thathsarani

A shop owner wants to store Item_number, and price of 10
products. After that he needs a program to display the details
of any product, when user enters desired item_number

Thathsarani

Please help me quickly