944,142 Members | Top Members by Rank

Ad:
Oct 5th, 2009
0

Help With Case Nesting(Restaurant Ordering Simulator)

Expand Post »
I have a problem with the Nesting of case statements.
This is a Simple restaurant program which simulates food ordering.
I used Case statements to Display Multiple nested menus base on the users choice
But i seem to have a problem with the esac,seems my nesting is wrong.Pleas any help or advice will be appreciated.


Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2.  
  3. clear
  4. # display menu
  5.  
  6. echo "-------------------------------"
  7. echo " Superman Restaurant"
  8. echo "-------------------------------"
  9. echo " Main Menu"
  10. echo "-------------------------------"
  11. echo " $(date)"
  12. echo "-------------------------------"
  13. echo "1. Display Meal Menu."
  14. echo "2. Display Drinks."
  15. echo "3. Display Desert."
  16. echo "4. Exit"
  17. # get input from the user
  18.  
  19. read -p "Enter your choice [ 1 -4 ] " choice
  20. # make decision using case..in..esac
  21. case $choice in
  22. 1)
  23. clear
  24. echo "-------------------------------"
  25. echo " Superman Restaurant"
  26. echo "-------------------------------"
  27. echo " Meal Menu"
  28. echo "-------------------------------"
  29. echo
  30. echo "1. Chichen Fried Rice 10RM."
  31. echo "2. Tom Yam Fried Rice 15RM."
  32. echo "3. Lovers Rice 10RM."
  33. echo "4. Curry Rice 12RM."
  34. echo "5. Jelof Rice 15RM."
  35. echo "6. Fairy Rice 10RM."
  36. echo "7. Spicy Stew Rice 18RM."
  37. echo "8. Exit"
  38.  
  39.  
  40. read -p "Enter your choice [ 1 -7 ] " Meal
  41. case $Meal in
  42. 1)
  43.  
  44. echo " You Just Selected Chichen Fried Rice"
  45.  
  46. read -p "Press [Enter] to continue order..."
  47.  
  48. if $readEnterKey true
  49. then
  50.  
  51. echo
  52. echo "Your Order has been Completed"
  53. else
  54. echo ""
  55. fi
  56.  
  57.  
  58.  
  59. ;;
  60.  
  61. 2)
  62. echo " You Just Selected Tom Yam Fried Rice"
  63.  
  64. read -p "Press [Enter] to continue order..."
  65. if $readEnterKey true
  66. then
  67.  
  68. echo
  69. echo "Your Order has been Completed"
  70. else
  71. echo ""
  72. fi
  73.  
  74.  
  75. ;;
  76.  
  77. 3)
  78. echo " You Just Selected Lovers Rice"
  79.  
  80.  
  81. read -p "Press [Enter] to continue order..."
  82. if $readEnterKey true
  83. then
  84.  
  85. echo
  86. echo "Your Order has been Completed"
  87. else
  88. echo ""
  89. fi
  90.  
  91.  
  92. ;;
  93. 4)
  94. echo " You Just Selected Curry Rice"
  95.  
  96. read -p "Press [Enter] to continue order..."
  97. if $readEnterKey true
  98. then
  99.  
  100. echo
  101. echo "Your Order has been Completed"
  102. else
  103. echo ""
  104. fi
  105.  
  106.  
  107. ;;
  108. 5)
  109. echo " You Just Selected Jelof Rice"
  110.  
  111. read -p "Press [Enter] to continue order..."
  112. if $readEnterKey true
  113. then
  114.  
  115. echo
  116. echo "Your Order has been Completed"
  117. else
  118. echo ""
  119. fi
  120.  
  121.  
  122. ;;
  123. 6)
  124. echo " You Just Selected Fairy Rice"
  125.  
  126. read -p "Press [Enter] to continue order..."
  127. if $readEnterKey true
  128. then
  129.  
  130. echo
  131. echo "Your Order has been Completed"
  132. else
  133. echo ""
  134. fi
  135.  
  136.  
  137. ;;
  138. 7)
  139. echo " You Just Selected Spicy Rice"
  140.  
  141. read -p "Press [Enter] to continue order..."
  142. if $readEnterKey true
  143. then
  144.  
  145. echo
  146. echo "Your Order has been Completed"
  147. else
  148. echo ""
  149. fi
  150.  
  151.  
  152. ;;
  153. 8)
  154.  
  155. echo "Bye!"
  156. exit 0
  157. ;;
  158. *)
  159. echo "Error: Invalid option..."
  160. read -p "Press [Enter] key to continue..."
  161.  
  162. ;;
  163.  
  164. esac
  165.  
  166.  
  167.  
  168.  
  169. 2)
  170. clear
  171. echo "-------------------------------"
  172. echo " Superman Restaurant"
  173. echo "-------------------------------"
  174. echo " Drinks Menu"
  175. echo "-------------------------------"
  176. echo
  177. echo "1. Kikapo Juice 2RM."
  178. echo "2. Orange Juice 3RM."
  179. echo "3. Apple Juice 3RM."
  180. echo "4. Lemon Ice Tea 1RM."
  181. echo "5. Mango Lassi 5RM."
  182. echo "6. Herba Tea 2RM."
  183. echo "7. Cococola 2RM"
  184. echo "8. Bye!"
  185. read -p "Enter your choice [ 1 -8 ] " Drinks
  186. case $Drinks in
  187. 1)
  188. echo " You Just Selected Kikapo Juice"
  189.  
  190. read -p "Press [Enter] to continue order..."
  191.  
  192. if $readEnterKey true
  193. then
  194.  
  195. echo
  196. echo "Your Order has been Completed"
  197. else
  198. echo ""
  199. fi
  200. 2)
  201. echo " You Just Selected Orange Juice"
  202.  
  203. read -p "Press [Enter] to continue order..."
  204.  
  205. if $readEnterKey true
  206. then
  207.  
  208. echo
  209. echo "Your Order has been Completed"
  210. else
  211. echo ""
  212. fi
  213. 3)
  214. echo " You Just Selected Apple Juice"
  215.  
  216. read -p "Press [Enter] to continue order..."
  217.  
  218. if $readEnterKey true
  219. then
  220.  
  221. echo
  222. echo "Your Order has been Completed"
  223. else
  224. echo ""
  225. fi
  226. 4)
  227. echo " You Just Selected Lemon Juice"
  228.  
  229. read -p "Press [Enter] to continue order..."
  230.  
  231. if $readEnterKey true
  232. then
  233.  
  234. echo
  235. echo "Your Order has been Completed"
  236. else
  237. echo ""
  238. fi
  239. 5)
  240. echo " You Just Selected Mango Juice"
  241.  
  242. read -p "Press [Enter] to continue order..."
  243.  
  244. if $readEnterKey true
  245. then
  246.  
  247. echo
  248. echo "Your Order has been Completed"
  249. else
  250. echo ""
  251.  
  252. fi
  253. 6)
  254. echo " You Just Selected Herbal Tea"
  255.  
  256. read -p "Press [Enter] to continue order..."
  257.  
  258. if $readEnterKey true
  259. then
  260.  
  261. echo
  262. echo "Your Order has been Completed"
  263. else
  264. echo ""
  265. fi
  266. 7)
  267. echo " You Just Selected Cocacola"
  268.  
  269. read -p "Press [Enter] to continue order..."
  270.  
  271. if $readEnterKey true
  272. then
  273.  
  274. echo
  275. echo "Your Order has been Completed"
  276. else
  277. echo ""
  278. fi
  279. 8)
  280.  
  281.  
  282. echo "Bye!"
  283. exit 0
  284. ;;
  285. *)
  286. echo "Error: Invalid option..."
  287. read -p "Press [Enter] key to continue..."
  288.  
  289. ;;
  290. esac
  291.  
  292.  
  293. 3)
  294.  
  295. clear
  296. echo "-------------------------------"
  297. echo " Superman Restaurant"
  298. echo "-------------------------------"
  299. echo " Desert Menu"
  300. echo "-------------------------------"
  301. echo
  302. echo "1. Ferry Cake 15RM."
  303. echo "2. Chocolate ice Cream 10RM."
  304. echo "3. Vanilla Cake 13RM."
  305. echo "4. Queen Cake 12RM."
  306. echo "5. Bye!"
  307. read -p "Enter your choice [ 1 -5 ] " Desert
  308. case $Desert in
  309. 1)
  310. echo " You Just Selected Ferry Cake"
  311.  
  312. read -p "Press [Enter] to continue order..."
  313.  
  314. if $readEnterKey true
  315. then
  316.  
  317. echo
  318. echo "Your Order has been Completed"
  319. else
  320. echo ""
  321. fi
  322. 2)
  323. echo " You Just Selected Chocolate ice Cream"
  324.  
  325. read -p "Press [Enter] to continue order..."
  326.  
  327. if $readEnterKey true
  328. then
  329.  
  330. echo
  331. echo "Your Order has been Completed"
  332. else
  333. echo ""
  334. fi
  335. 3)
  336. echo " You Just Selected Vanilla Cake"
  337.  
  338. read -p "Press [Enter] to continue order..."
  339.  
  340. if $readEnterKey true
  341. then
  342.  
  343. echo
  344. echo "Your Order has been Completed"
  345. else
  346. echo ""
  347. fi
  348. 4)
  349. echo " You Just Selected Queen Cake"
  350.  
  351. read -p "Press [Enter] to continue order..."
  352.  
  353. if $readEnterKey true
  354. then
  355.  
  356. echo
  357. echo "Your Order has been Completed"
  358. else
  359. echo ""
  360.  
  361. fi
  362. 5)
  363.  
  364.  
  365. echo "Bye!"
  366. exit 0
  367. ;;
  368. *)
  369. echo "Error: Invalid option..."
  370. read -p "Press [Enter] key to continue..."
  371.  
  372. ;;
  373. esac
  374.  
  375.  
  376.  
  377.  
  378.  
  379. 4)
  380.  
  381. echo "Bye!"
  382. exit 0
  383. ;;
  384. *)
  385. echo "Error: Invalid option..."
  386. read -p "Press [Enter] key to continue..."
  387.  
  388. ;;
  389.  
  390.  
  391.  
  392. esac
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
frankycool is offline Offline
15 posts
since Sep 2009
Oct 7th, 2009
0
Re: Help With Case Nesting(Restaurant Ordering Simulator)
You are missing ;; before 2) on line 168 or thereabouts and in many other places.
Last edited by cfajohnson; Oct 7th, 2009 at 7:49 am.
Reputation Points: 25
Solved Threads: 23
Junior Poster
cfajohnson is offline Offline
193 posts
since Dec 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Log file analysis based on time range
Next Thread in Shell Scripting Forum Timeline: Can somebody help with looping my command?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC