This should be a relatively simple c language program. Because the school c language class ended early, I learned the structure pointer at that time, so I applied all the knowledge points I could use at that time to this program. Although this program was the ceiling for me at that time, when I continued to study, I gradually found that there were too many points that this program could be upgraded. But I haven't improved emmmm (actually lazy). So I hardened my scalp and sent him out.
Knowledge points involved in the code: sequential structure, selection branch structure, circular structure, array, user-defined function, pointer and structure.
The main ideas are:
A struct array defined by contains three members, namely, dish number (serial_number), dish name (dishes_name[50]), and meal price (money). Define a structure array dishes[50] and assign a value to it. Then define multiple functions and use multiple printf to output the interactive page respectively. For example, the start interface is named outside, the welcome interface is named welcome, the menu function is named menu, the waiting function is named waiting, the bill function is named bill, the send off function is named goodbye, and the background function is named backstage_welcome. These are the required parts of the main function.
The nodes that can be used by goto are set many times in the program for return after use to make the program more complete. And reasonably use the screen clearing function system("cls");, Keep the program on the introduction page.
The main functions of the ordering system are:
(1) enter the table number and number of people before ordering
(2) menu browsing function
(3) enter the selected menu
(4) calculate the total amount of the bill;
(5) sorting and other functions according to the order of dishes;
(6) deletion and modification of dish information;
The hard to understand knowledge points are:
In the menu function, the value entered is the structure address, which is convenient for numerical reference in the table. \t is used to align and make the interface cleaner. \n is enter. b in struct menu* b represents the address of struct menu, b points to the first address of struct, that is, struct array dishes[1], b+1 points to struct array dishes[2], and so on. - > Represents a value that references a member under the address. Output the corresponding value in the structure array with% d,% s.
In the user-defined bill function, it is used to output the dish number and name, and calculate the total amount. NUM[50] stores the dish number entered by the user, struct menu* b is used to call the corresponding dish name when outputting the menu, and paymonth is used to input the total amount calculated in the main function. Then define an integer variable i to count the for loop. Set i to 0 and execute the following loop structure. if is the key to judge the end of the loop. After looping to 0 in the input array int NUM[50], break ends the loop. if it is not 0, continue to output the menu. After the cycle ends, the total amount is output.
The screen clearing function is in #include < conio h> Yes.
Experimental problems
The strcmp function should be used for array assignment, and the structure pointer cannot be called, because the array name in the structure is its first address, and then the address will report an error.
When using the screen clearing function, you should add a getch or scanf to prevent screen clearing before output.
It solves the problem that the dish name cannot be entered when modifying the dish name in the program background system. A line of getch should be added to eat the entered carriage return.
The code is as follows:
#include<stdio.h> #include<conio.h> #include<string.h> struct menu { int serial_number; char dishes_name[50]; int money; }dishes[50]={ {1,"Mapo Tofu",20}, {2,"Fish flavored shredded chicken",25}, {3,"Beijing Roast Duck",67}, {4,"Stew in disorder",54}, {5,"Kelp silk",12}, {6,"Potato silk",12}, {7,"Cola Chicken Wings",44}, {8,"Decimeter chicken",77}, {9,"Beef noodles",24}, {10,"Baked Scallion Pancake",5}, {11,"rice",3} }; int outside(void) { printf("--------------------------------\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| Welcome to the restaurant ordering system |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("--------------------------------\n"); } int welcome(int PEOPLENUMBER,int DESK) { printf("--------------------------------\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| The first%d No%d Guests, welcome |\n",PEOPLENUMBER,DESK); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("--------------------------------\n"); } int menu(struct menu* b) { printf("------number------name-----Price---\n"); printf("| %d\t %s\t %d\t |\t\n",(b)->serial_number,(b)->dishes_name,(b)->money); printf("| %d\t %s\t %d\t |\t\n",(b+1)->serial_number,(b+1)->dishes_name,(b+1)->money); printf("| %d\t %s\t %d\t |\t\n",(b+2)->serial_number,(b+2)->dishes_name,(b+2)->money); printf("| %d\t %s\t %d\t |\t\n",(b+3)->serial_number,(b+3)->dishes_name,(b+3)->money); printf("| %d\t %s\t %d\t |\t\n",(b+4)->serial_number,(b+4)->dishes_name,(b+4)->money); printf("| %d\t %s\t %d\t |\t\n",(b+5)->serial_number,(b+5)->dishes_name,(b+5)->money); printf("| %d\t %s\t %d\t |\t\n",(b+6)->serial_number,(b+6)->dishes_name,(b+6)->money); printf("| %d\t %s\t %d\t |\t\n",(b+7)->serial_number,(b+7)->dishes_name,(b+7)->money); printf("| %d\t %s\t %d\t |\t\n",(b+8)->serial_number,(b+8)->dishes_name,(b+8)->money); printf("| %d\t%s\t %d\t |\t\n",(b+9)->serial_number,(b+9)->dishes_name,(b+9)->money); printf("| %d\t%s\t %d\t |\t\n",(b+10)->serial_number,(b+10)->dishes_name,(b+10)->money); printf("--------------------------------\n"); } int waiting(void) { printf("--------------------------------\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| Your menu has been received. Please wait for your meal |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("--------------------------------\n"); } int bill(int NUM[50],struct menu* b,int PAYMONEY) { printf("--------------------------------\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| Please check your bill |\n"); printf("| If you have any objection, please contact the waiter |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("--------------------------------\n"); int i; for(i=0;;i++) { if(NUM[i]==0) { break; } printf(" %d\t %s\t %d\t\n",NUM[i],(b+NUM[i]-1)->dishes_name,(b+NUM[i]-1)->money); } printf("Total%d element\n",PAYMONEY); } int goodbye(void) { printf("--------------------------------\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| Thank you for your review |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("| |\n"); printf("--------------------------------\n"); } int backstage_welcome(void) { printf("--------------------------------\n"); printf("| |\n"); printf("| Welcome to the background management system |\n"); printf("| |\n"); printf("| |\n"); printf("| Please enter 1 to modify the price |\n"); printf("| |\n"); printf("| Please enter 2 to modify the dishes |\n"); printf("| |\n"); printf("| Please enter 3 to exit the administrator interface |\n"); printf("| |\n"); printf("| |\n"); printf("--------------------------------\n"); } int main() { start: outside(); int desknumber,human; int n,i,num[50],paymoney=0; int keyword; int change; struct menu* pmenu=&dishes; printf("Please enter the table number(Enter 1009 to enter the management interface)"); scanf("%d",&desknumber); if(desknumber==1009) { goto start_backstage; } printf("Please enter the number of diners"); scanf("%d",&human); system("cls"); welcome(human,desknumber); printf("Enter any Arabic numerals and click enter to enter the next step"); scanf("%d"); system("cls"); menu(pmenu); pmenu=&dishes; printf("Please enter the number of the dish you want to eat. You can enter multiple numbers at one time. After each number, please enter "," and end with 0\n"); for(i=0;;i++) { scanf("%d,",&num[i]); if(num[i]==0) { break; } else { paymoney+=((pmenu+num[i]-1)->money); } } system("cls"); waiting(); start_to_bill: printf("Please enter 1 to view the bill\n"); scanf("%d",&n); system("cls"); start_to_pay: if(n==1) { bill(num,pmenu,paymoney); } else { printf("Input error, please re-enter\n"); goto start_to_bill; } printf("We have contacted the waiter for you. The waiter will arrive soon. Please wait a moment\n"); printf("Ask the waiter to confirm and enter the password (1111)\n"); scanf("%d",&keyword); system("cls"); if(keyword==1111) { goodbye(); printf("Please enter any Arabic numerals to reset the ordering system\n"); scanf("%d"); system("cls"); goto start; } else { printf("Input error, please re-enter\n"); goto start_to_pay; } start_backstage: printf("Please enter the administrator password (1111)"); scanf("%d",&keyword); if(keyword!=1111) { printf("Password error,Enter an Arabic numeral at will and return"); scanf("%d"); system("cls"); goto start; } system("cls"); start_manage: backstage_welcome(); scanf("%d",&change); if(change==1) { int bianhao,changemoney; printf("Please enter the dish number"); scanf("%d",&bianhao); printf("\n Please enter the modified price\n"); scanf("%d",&changemoney); (pmenu+bianhao-1)->money=changemoney; printf("Modified successfully,Enter any Arabic numerals to return to the administrator interface\n"); scanf("%d"); system("cls"); goto start_manage; } else if(change==3) { system("cls"); goto start; } else if(change==2) { int bianhao; char dish_name[50]; char *pname=&(pmenu+bianhao-1)->dishes_name; printf("Please enter the dish number"); scanf("%d",&bianhao); getchar(); printf("\n Please enter a name for the modification\n"); gets(dish_name); strcpy(dishes[bianhao-1].dishes_name,dish_name); //strcpy(pname,dish_name); printf("Modified successfully,Enter any Arabic numerals to return to the administrator interface\n"); scanf("%d"); system("cls"); goto start_manage; } else { printf("Please enter a valid number"); system("cls"); goto start_manage; } }
There are many points that this program can be upgraded. For example, you can write a linked list and automatically enter the name and price of dishes; You can also define a file pointer, and use fopen and fclose to save the menu and pipeline in a txt file for subsequent reference.