Advertisement
Guest User

mine

a guest
Aug 21st, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. Console.Write("Enter weight of parcel: ");
  2. string input = Console.ReadLine();
  3.  
  4. class Program
  5. {
  6. private static int _depth = 0;
  7. private static int _height = 0;
  8. private static int _weight = 0;
  9. private static int _width = 0;
  10. private static bool _isInvalidInput = true;
  11. static void Main(string[] args)
  12. {
  13. GetWeightInput();
  14. GetHeightInput();
  15. GetWidthInput();
  16. GetDepthInput();
  17.  
  18. Console.ReadLine();
  19. }
  20. private static void GetWeightInput()
  21. {
  22. while(_isInvalidInput)
  23. {
  24. Console.Write("Enter weight of parcel: ");
  25. string input = Console.ReadLine();
  26.  
  27. #region User Weight Input Validation
  28. if (int.TryParse(input, out _weight))
  29. {
  30. _isInvalidInput = false;
  31. //TODO: Add More Validations of User Input
  32. }
  33. else
  34. {
  35. Console.WriteLine("***Only Integer Inputs Are Allowed***");
  36. _isInvalidInput = true;
  37. }
  38. #endregion User Weight Input Validation
  39. }
  40.  
  41.  
  42. _isInvalidInput = true;//reset value to true
  43. }
  44. private static void GetHeightInput()
  45. {
  46. while (_isInvalidInput)
  47. {
  48. Console.Write("Enter weight of parcel: ");
  49. string input = Console.ReadLine();
  50.  
  51. #region User Weight Input Validation
  52. if (int.TryParse(input, out _height))
  53. {
  54. _isInvalidInput = false;
  55. //TODO: Add More Validations of User Input
  56. }
  57. else
  58. {
  59. Console.WriteLine("***Only Integer Inputs Are Allowed***");
  60. _isInvalidInput = true;
  61. }
  62. #endregion User Weight Input Validation
  63. }
  64.  
  65.  
  66. _isInvalidInput = true;//reset value to true
  67. }
  68. private static void GetWidthInput()
  69. {
  70. while (_isInvalidInput)
  71. {
  72. Console.Write("Enter weight of parcel: ");
  73. string input = Console.ReadLine();
  74.  
  75. #region User Weight Input Validation
  76. if (int.TryParse(input, out _width))
  77. {
  78. _isInvalidInput = false;
  79. //TODO: Add More Validations of User Input
  80. }
  81. else
  82. {
  83. Console.WriteLine("***Only Integer Inputs Are Allowed***");
  84. _isInvalidInput = true;
  85. }
  86. #endregion User Weight Input Validation
  87. }
  88.  
  89.  
  90. _isInvalidInput = true;//reset value to true
  91. }
  92. private static void GetDepthInput()
  93. {
  94. while (_isInvalidInput)
  95. {
  96. Console.Write("Enter weight of parcel: ");
  97. string input = Console.ReadLine();
  98.  
  99. #region User Weight Input Validation
  100. if (int.TryParse(input, out _width))
  101. {
  102. _isInvalidInput = false;
  103. //TODO: Add More Validations of User Input
  104. }
  105. else
  106. {
  107. Console.WriteLine("***Only Integer Inputs Are Allowed***");
  108. _isInvalidInput = true;
  109. }
  110. #endregion User Weight Input Validation
  111. }
  112.  
  113.  
  114. _isInvalidInput = true;//reset value to true
  115. }
  116. }
  117.  
  118. static void Main(string[] args)
  119. {
  120. GetWeightInput();
  121. GetHeightInput();
  122. GetWidthInput();
  123. GetDepthInput();
  124.  
  125. Console.ReadLine();
  126. }
  127.  
  128. static void Main(string[] args)
  129. {
  130. var weight = AskInteger("Enter weight of parcel: ");
  131. var height = AskInteger("Enter height of parcel: ");
  132. var width = AskInteger("Enter width of parcel: ");
  133. var depth = AskInteger("Enter depth of parcel: ");
  134.  
  135. Console.WriteLine("press any key to terminate the application..");
  136. Console.ReadKey(true);
  137. }
  138.  
  139. static void Main(string[] args)
  140. {
  141. var request = new Request();
  142. AskInteger(request, x => x.Weight);
  143. AskInteger(request, x => x.Height);
  144. AskInteger(request, x => x.Width);
  145. AskInteger(request, x => x.Depth);
  146.  
  147. Console.WriteLine("press any key to terminate the application..");
  148. Console.ReadKey(true);
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement