An order ordering system based on C language is implemented

  • 2020-06-19 11:30:50
  • OfStack

The example of this paper shares the specific code of C language ordering system for your reference. The specific content is as follows

Simple restaurant ordering system written in C language, simple operation, not much code, menu can be changed by themselves, the price is also


#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include"windows.h"
struct cai /*cai The structure of the body   Realize the dishes   Number of copies, name, raw material   The record of */
{
 int fenshu;
 char name[50];
 int use;
 int price;
};
typedef int ElemType;
struct List /* The linear table can record the surplus amount of the raw materials. The linear table [ i ] The code of the corresponding menu */
{ 
 ElemType* list;
 int size;
 int MaxSize;
};
/* The following are functions of a linear table */
void InitList(struct List* L,int ms)  
{
 if(ms<=0){printf("ms  Value is illegal! \n");exit(1);}
 L->MaxSize=ms;
 L->list=malloc(ms*sizeof(ElemType));
 if(!L->list)
 {
 printf(" Dynamic storage allocation failed! ");
  exit(1);
 }
 L->size=0;
}
void againMalloc(struct List *L)
{
 ElemType *p=realloc(L->list,2*L->MaxSize*sizeof(ElemType));
 if(!p){
 printf(" Failed to allocate storage space! ");
 exit(1);
 }
L->list=p;
L->MaxSize=2*L->MaxSize;
}
void InsertLastList(struct List *L,ElemType x)
{
 if(L->size==L->MaxSize)
 againMalloc(L);
 L->list[L->size]=x;
 L->size++;
}
/* Form and function */
void cddayin(struct cai a[])
{
 int i=0,j=0,s=0;
 for(i=0;i<30;i++)
 {if(a[i].fenshu>0) j++;}
 if(j!=0)
 {
 printf(" Have to order / Wine product serial number    Order the name of the dish    Have some copies / bottle    The price \n");
  for(i=0;i<30;i++)
  if(a[i].fenshu>0) 
 {printf(" %5d     %10s%14d    %d RMB   \n",i,a[i].name,a[i].fenshu,a[i].fenshu*a[i].price);
 s=s+a[i].fenshu*a[i].price;
 } 
  printf("            Hello, the total price of your order =%d RMB \n",s);
 }
 if(j==0)
  printf(" The customer has not ordered yet , Unable to print menu !\n");
}
void ycliao(struct List *yuan,struct cai a[])
{
 int i=1,p=0,k=0;
 for(i=0;i<30;i++)
 {
 do{
 p=a[i].use%100;
 yuan->list[p]=yuan->list[p]-a[i].fenshu;
 a[i].use=a[i].use/100;
 }while(a[i].use!=0);
 } 
 printf("|-------------------------------------------------------|--------------------|\n");
 printf("|------------------ Raw material allowance ---------------------------|----- Wine allowance -------|\n");
 printf("|-------------------------------------------------------|--------------------|\n");
 printf("| 10. chicken =%3d  11. pork =%3d   12. fish =%3d | 50. Snowflakes beer =%3d |\n",yuan->list[10],yuan->list[11],yuan->list[12],yuan->list[50]);
 printf("| 13. cucumber =%3d  14. potatoes =%3d   15. tofu =%3d | 51. Yanjing beer =%3d |\n",yuan->list[13],yuan->list[14],yuan->list[15],yuan->list[51]);
 printf("| 16. eggplant =%3d  17. Green peppers =%3d   18. beef =%3d | 52.2 Pan head =%3d  |\n",yuan->list[16],yuan->list[17],yuan->list[18],yuan->list[52]);
 printf("| 19. Green Chinese onion =%3d  20. Fresh duck blood =%3d  21. peanut =%3d |     |\n",yuan->list[19],yuan->list[20],yuan->list[21]);
 printf("| 22. Chinese prickly ash =%3d  23. sauce =%3d   24. carrot =%3d |     |\n",yuan->list[22],yuan->list[23],yuan->list[24]);
 printf("| 25. chili =%3d  26. celery =%3d   27. Bean curd =%3d |     |\n",yuan->list[25],yuan->list[26],yuan->list[27]);
 printf("|-------------------------------------------------------|--------------------|\n");
 printf("|-------------------------------------------------------|--------------------|\n");
}
void diancai(struct cai a[])
{ 
 int p=0,wep=0;
 do{
 printf("  |----------------------------------------------|-------------------|\n");
 printf("  |---------- dishes ( The input -1 Confirm and finish your order )----------|------- wine --------|\n");
 printf("  |----------------------------------------------|-------------------|\n");
 printf("  | 1. Kung pao chicken   2. Braised pork   3. Sautéed Shredded Pork in Sweet Bean Sauce  | 21. Snowflakes beer   |\n");
 printf("  | 4. to 3 fresh    5. Boiled fish    6. The bean curd  | 22. Yanjing beer   |\n");
 printf("  | 7. Sliced Beef and Ox Tongue in Chili Sauce   8. Take the cucumber    9. Fresh duck blood  | 23.2 Pan head   |\n");
 printf("  |----------------------------------------------|-------------------|\n");
 printf("  |----------------------------------------------|-------------------|\n");
 scanf("%d",&p);
 system("CLS");
 if(p>=1&&p<=9)
 {
 printf("   |------------------------------------------|\n");
  printf("   |------------------ Additional copies --------------------|\n");
  printf("   |------------------------------------------|\n");
  printf("   | 1.1 Copy of the    2. Two copies of      |\n");
  printf("   | 3.3 Copy of the    4. Others please input directly   |\n"); 
  printf("   |------------------------------------------|\n");
  printf("   |------------------------------------------|\n");
 scanf("%d",&wep);
 if(wep>50)
 {system("CLS");printf(" The value you entered is abnormal or too large, please check the value you entered! \n");continue;}/* Prevent misinput */
 else if(wep<=50)
 {a[p].fenshu+=wep;
  system("CLS");
 }
 }
 else if(p>=21&&p<=23)
 {
 
  printf("   |--------------------------------------------------------|\n");
  printf("   |------------------------- Number of drinks -----------------------|\n");
  printf("   |--------------------------------------------------------|\n");
  printf("   | 1.1 bottle  2. Two bottles of  3.3 bottle  4. Please input other bottles directly   |\n"); 
  printf("   |--------------------------------------------------------|\n");
  printf("   |--------------------------------------------------------|\n");
 scanf("%d",&wep);
 if(wep>50)
 {system("CLS");printf(" The value you entered is abnormal or too large, please check the value you entered! \n");continue;}/* Prevent misinput */
 else if(wep<=50)
 {
 a[p].fenshu+=wep;
  system("CLS");
 }
 }
 else if(p!=-1)
 printf(" Sorry, the code you entered does not correspond to the dishes, please re-enter! \n"); 
 }while(p!=-1);
 system("CLS");
 cddayin(a);
}
void ycldayin(struct List yuan,struct cai a[])
{
 char l='\0';
 printf(" Show raw material allowance ? ( Y/N ) \n");
 l=getch();
 if(l=='Y'||l=='y')
 {system("CLS");
 ycliao(&yuan,a);}
 else
 { system("CLS");
 printf("\n\n\n\n");}
} 
main()
{
 
 int i=0;
 char l='\0';
 struct List yuan;   /* yuan Don't put "before". * "  */
 struct cai a[30]={
 {0,"\0",0},
 {0," Kung pao chicken ",10131421,15},{0," Braised pork ",1124,14},{0," Sautéed Shredded Pork in Sweet Bean Sauce ",112327,16},
 {0," to 3 fresh ",141617,10},{0," Boiled fish ",122225,50},{0," The bean curd ",152225,11},
 {0," Sliced Beef and Ox Tongue in Chili Sauce ",18212625,17},{0," Take the cucumber ",13252223,8},{0," Fresh duck blood ",20,20},
 {0,"\0",0},{0,"\0",0},{0,"\0",0},
 {0,"\0",0},{0,"\0",0},{0,"\0",0},
 {0,"\0",0},{0,"\0",0},{0,"\0",0},
 {0,"\0",0},{0,"\0",0},
 {0," Snowflakes beer ",50,5},{0," Yanjing beer ",51,6},{0,"2 Pan head ",52,4},
 {0,"\0",0},{0,"\0",0},{0,"\0",0},
 {0,"\0",0},{0,"\0",0},{0,"\0",0}};
 InitList(&yuan,60);
  for(i=0;i<60;i++)
 InsertLastList(&yuan,100);//+rand()%50
  printf("\n\n\n\n\n\n\n\n");
  printf("   |--------------------------------------------------------|\n");
  printf("   |----------------  Welcome to chunxiao Ordering system ! -----------------|\n"); 
  printf("   |--------------------------------------------------------|\n");
 Sleep(2500);
  system("CLS");
  diancai(a);    /* Order function, order! */
 ycldayin(yuan,a);
 printf("\n\n\n\n");
  printf("   |--------------------------------------------------------|\n");
  printf("   |--------------  Welcome to chunxiao ordering system again ! ---------------|\n"); 
  printf("   |--------------------------------------------------------|\n");
 printf("\n\n\n\n\n\n");
}

For more information, please pay attention to the topic management System Development.


Related articles: