Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.93 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4.  
  5. struct menu
  6. {
  7. int id;
  8. char name[20];
  9. char make[20];
  10. int numserve;
  11. float price;
  12. };
  13.  
  14. void addMenu();
  15. void displayAll();
  16.  
  17. int counter=1;
  18. int choice1,choice2,choice3;
  19. int main()
  20. {
  21.  
  22.  
  23.  
  24. main:
  25. system("cls");
  26. printf("\t =======================Toms Restaurant=======================\n");
  27. printf("1 - Add Menu\n");
  28. printf("2 - Update Menu\n");
  29. printf("3 - Display All\n");
  30. printf("4 - Order Menu\n");
  31. printf("5 - Total Sales\n");
  32. printf("6 - Exit\n");
  33.  
  34. printf("Please input a number to select: \n\n");
  35. scanf("%d",&choice1);
  36.  
  37. switch(choice1)
  38. {
  39. case 1: addMenu();
  40. goto main; // function
  41. break;
  42. case 2: goto main; //function
  43. system("cls");
  44. break;
  45. case 3: displayAll(); //function
  46. system("pause");
  47. break;
  48. case 4: goto menu;
  49. system("cls");
  50. break;
  51. case 5: goto main;
  52. system("cls");
  53. break;
  54. case 0: exit(0);
  55. break;
  56. default: goto main;
  57. system("cls");
  58.  
  59. }
  60.  
  61. menu:
  62. system("cls");
  63. printf("1 - Select Menu\n");
  64. printf("2 - Best Seller\n");
  65. printf("3 - Back\n\n");
  66. printf("Please input a number to select:");
  67. scanf("%d",&choice2);
  68.  
  69. switch(choice2)
  70. {
  71. case 1: goto select;
  72. system("cls");
  73. break;
  74. case 2: goto main;
  75. break;
  76. case 3: goto main;
  77. break;
  78. }
  79.  
  80. select:
  81. system("cls");
  82. printf("1 - Appetizers\n");
  83. printf("2 - Entrees\n");
  84. printf("3 - Dessert\n");
  85. printf("4 - Beverage\n");
  86. printf("5 - Back\n\n");
  87. printf("Please input a number to select:");
  88. scanf("%d",&choice3);
  89.  
  90. switch(choice3)
  91. {
  92. case 1: goto select;
  93. system("cls");
  94. break;
  95. case 2: goto select;
  96. system("cls");
  97. break;
  98. case 3: goto select;
  99. system("cls");
  100. break;
  101. case 4: goto select;
  102. system("cls");
  103. break;
  104. case 5: goto menu;
  105. system("cls");
  106. break;
  107. default: system("cls");
  108. goto select;
  109. break;
  110. }
  111. getch();
  112. }
  113.  
  114. void addMenu()
  115. {
  116. system("cls");
  117. FILE *fp;
  118. struct menu menus;
  119. int numofentrees;
  120. int i;
  121. fp=fopen("storage.dat","ab");
  122. if(fp == NULL)
  123. printf("The file does not exist!");
  124. else
  125. {
  126. printf("Number of Menu Added: ");
  127. scanf("%d",&numofentrees);
  128. if(numofentrees > 30)
  129. {
  130. printf("Insufficient storage (Max: 30)\n");
  131. system("pause");
  132. }
  133. else if(numofentrees > 0)
  134. {
  135.  
  136. while(numofentrees > 0)
  137. {
  138.  
  139. printf("\nID #: %d",counter++);
  140. fflush(stdin);
  141. printf("\nEnter Menu Name: ");
  142. scanf("%[^\n]s",&menus.name);
  143. fflush(stdin);
  144. printf("Enter what the menu made of (pork,beef,chicken): ");
  145. fflush(stdin);
  146. scanf("%[^\n]s",&menus.make);
  147. printf("Number of Servings: ");
  148. fflush(stdin);
  149. scanf("%d",&menus.numserve);
  150. fflush(stdin);
  151. printf("Price: ");
  152. scanf("%f",&menus.price);
  153. fflush(stdin);
  154. fwrite(&menus, 1, sizeof(menus), fp);
  155. numofentrees--;
  156.  
  157. }
  158. fclose(fp);
  159. }
  160. }
  161.  
  162. }
  163.  
  164. void displayAll()
  165. {
  166. system("cls");
  167. FILE *fp;
  168. struct menu menus;
  169. fp = fopen("storage.dat","rb+");
  170. if(fp == NULL)
  171. {
  172. printf("The file does not exist!");
  173. }
  174. else
  175. {
  176. printf("The file is successfully openned!\n\n");
  177. }
  178. printf("%-5s%-15s%-15s%-15s%-15s\n", "ID", "NAME", "INGREDIENTS", "# OF SERVINGS", "PRICE");
  179.  
  180. while(1)
  181. {
  182. fread(&menus, 1, sizeof(menus), fp);
  183. if(feof(fp))
  184. break;
  185. printf("%-5d%-15s%-15s%-17d%-15d\n", counter, menus.name, menus.make, menus.numserve, menus.price);
  186. }
  187. fclose(fp);
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement