Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<stdlib.h>
- struct menu
- {
- int id;
- char name[20];
- char make[20];
- int numserve;
- float price;
- };
- void addMenu();
- void displayAll();
- int counter=1;
- int choice1,choice2,choice3;
- int main()
- {
- main:
- system("cls");
- printf("\t =======================Toms Restaurant=======================\n");
- printf("1 - Add Menu\n");
- printf("2 - Update Menu\n");
- printf("3 - Display All\n");
- printf("4 - Order Menu\n");
- printf("5 - Total Sales\n");
- printf("6 - Exit\n");
- printf("Please input a number to select: \n\n");
- scanf("%d",&choice1);
- switch(choice1)
- {
- case 1: addMenu();
- goto main; // function
- break;
- case 2: goto main; //function
- system("cls");
- break;
- case 3: displayAll(); //function
- system("pause");
- break;
- case 4: goto menu;
- system("cls");
- break;
- case 5: goto main;
- system("cls");
- break;
- case 0: exit(0);
- break;
- default: goto main;
- system("cls");
- }
- menu:
- system("cls");
- printf("1 - Select Menu\n");
- printf("2 - Best Seller\n");
- printf("3 - Back\n\n");
- printf("Please input a number to select:");
- scanf("%d",&choice2);
- switch(choice2)
- {
- case 1: goto select;
- system("cls");
- break;
- case 2: goto main;
- break;
- case 3: goto main;
- break;
- }
- select:
- system("cls");
- printf("1 - Appetizers\n");
- printf("2 - Entrees\n");
- printf("3 - Dessert\n");
- printf("4 - Beverage\n");
- printf("5 - Back\n\n");
- printf("Please input a number to select:");
- scanf("%d",&choice3);
- switch(choice3)
- {
- case 1: goto select;
- system("cls");
- break;
- case 2: goto select;
- system("cls");
- break;
- case 3: goto select;
- system("cls");
- break;
- case 4: goto select;
- system("cls");
- break;
- case 5: goto menu;
- system("cls");
- break;
- default: system("cls");
- goto select;
- break;
- }
- getch();
- }
- void addMenu()
- {
- system("cls");
- FILE *fp;
- struct menu menus;
- int numofentrees;
- int i;
- fp=fopen("storage.dat","ab");
- if(fp == NULL)
- printf("The file does not exist!");
- else
- {
- printf("Number of Menu Added: ");
- scanf("%d",&numofentrees);
- if(numofentrees > 30)
- {
- printf("Insufficient storage (Max: 30)\n");
- system("pause");
- }
- else if(numofentrees > 0)
- {
- while(numofentrees > 0)
- {
- printf("\nID #: %d",counter++);
- fflush(stdin);
- printf("\nEnter Menu Name: ");
- scanf("%[^\n]s",&menus.name);
- fflush(stdin);
- printf("Enter what the menu made of (pork,beef,chicken): ");
- fflush(stdin);
- scanf("%[^\n]s",&menus.make);
- printf("Number of Servings: ");
- fflush(stdin);
- scanf("%d",&menus.numserve);
- fflush(stdin);
- printf("Price: ");
- scanf("%f",&menus.price);
- fflush(stdin);
- fwrite(&menus, 1, sizeof(menus), fp);
- numofentrees--;
- }
- fclose(fp);
- }
- }
- }
- void displayAll()
- {
- system("cls");
- FILE *fp;
- struct menu menus;
- fp = fopen("storage.dat","rb+");
- if(fp == NULL)
- {
- printf("The file does not exist!");
- }
- else
- {
- printf("The file is successfully openned!\n\n");
- }
- printf("%-5s%-15s%-15s%-15s%-15s\n", "ID", "NAME", "INGREDIENTS", "# OF SERVINGS", "PRICE");
- while(1)
- {
- fread(&menus, 1, sizeof(menus), fp);
- if(feof(fp))
- break;
- printf("%-5d%-15s%-15s%-17d%-15d\n", counter, menus.name, menus.make, menus.numserve, menus.price);
- }
- fclose(fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement