Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<stdlib.h>
- int count=0;
- void insert_prod();//declaration
- void view_prod();
- void search_prod1();
- struct prod
- {
- int pid;
- char pname[20];
- int qty;
- int price;
- int total;
- }p[5];
- void main()
- {
- //struct prod p[5];//array of structure
- int ch;
- clrscr();
- do
- {
- printf("\n 1. Insert product information");
- printf("\n 2. View product information");
- printf("\n 3. Search product price");
- printf("\n 4. Search product name");
- printf("\n 5. Exit");
- printf("\n Enter your choice");
- scanf("%d",&ch);
- switch(ch)
- {
- case 1:
- insert_prod();//user deinfe function calling
- break;
- case 2:
- view_prod();
- break;
- case 3:
- search_prod1();
- break;
- }
- }while(ch>=1 && ch<=4);
- getch();
- }
- void insert_prod() //definatino
- {
- if(count==5)
- {
- printf("\n Sorry no more record is inserted...");
- }
- else
- {
- printf("\n Enter product Id=");
- scanf("%d",&p[count].pid);
- printf("\n Enter proudct Name=");
- flushall();
- gets(p[count].pname);
- printf("\n Enter proudct price=");
- scanf("%d",&p[count].price);
- printf("\n Enter product qty=");
- scanf("%d",&p[count].qty);
- p[count].total=p[count].price*p[count].qty;
- count++;
- }
- }
- void view_prod()
- {
- int i=0;
- if(count==0)
- {
- printf("\n No record found...");
- }
- else
- {
- printf("\n ======= Product Information ====== ");
- for(i=0;i<count;i++)
- {
- printf("\n%d \t %s \t %d \t %d \t %d",p[i].pid,p[i].pname,p[i].price,p[i].qty,p[i].total);
- }
- }
- }
- void search_prod1()
- {
- int temp,i;
- if(count==0)
- {
- printf("\n No record found...");
- }
- else
- {
- printf("\n Enter price you want to search");
- scanf("%d",&temp);
- for(i=0;i<count;i++)
- {
- if(p[i].price >= temp)
- {
- printf("\n%d \t %s \t %d \t %d \t %d",p[i].pid,p[i].pname,p[i].price,p[i].qty,p[i].total);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment