Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1.  
  2. namespace WhileLoops
  3. {
  4. class Program
  5. {
  6. static void Main(string[] args)
  7. {
  8. bool displayMenu = true;
  9.  
  10. while (displayMenu)
  11. {
  12. displayMenu = MainMenu();
  13. }
  14. }
  15. private static bool MainMenu()
  16. {
  17. Console.WriteLine("Choose an option: ");
  18. Console.WriteLine("1) Option 1 ");
  19. Console.WriteLine("2) Option 2 ");
  20. Console.WriteLine("3) Exit");
  21. string result = Console.ReadLine();
  22.  
  23. if (result == "1")
  24. {
  25. Option1();
  26. return true;
  27. }
  28. else if (result == "2")
  29. {
  30. Option2();
  31. return true;
  32. }
  33. else if (result == "3")
  34. {
  35. Exit();
  36. return false;
  37. }
  38. else
  39. {
  40. InvalidInput();
  41. return true;
  42. }
  43. }
  44. private static void Option1()
  45. {
  46. Console.WriteLine("Option 1 sub-menu");
  47. Console.ReadLine();
  48. }
  49. private static void Option2()
  50. {
  51. Console.WriteLine("Option 2 sub-menu");
  52. Console.ReadLine();
  53. }
  54. private static void Exit()
  55. {
  56.  
  57. }
  58. private static void InvalidInput()
  59. {
  60. Console.WriteLine("Sorry, we do not understand");
  61. Console.ReadLine();
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement