Advertisement
Iv555

Untitled

Mar 8th, 2022
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. using System;
  2.  
  3. namespace T02EnterNumbersVer2
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int start = 1;
  10. int end = 100;
  11. int[] array = new int[10];
  12. for (int i = 0; i < 10; i++)
  13. {
  14. array[i] = ReadNumber(start, end);
  15. if (array[i] <= start)
  16. {
  17. i--;
  18. }
  19. else
  20. {
  21. start = array[i];
  22. }
  23.  
  24. }
  25.  
  26. Console.WriteLine(string.Join(", ", array));
  27.  
  28. }
  29.  
  30. public static int ReadNumber(int start, int end)
  31. {
  32. int readValue = 0;
  33. string input = Console.ReadLine();
  34.  
  35. try
  36. {
  37. if (int.TryParse(input, out readValue) == false)
  38. {
  39. throw new FormatException();
  40.  
  41. }
  42. if (readValue >= end || readValue <= start)
  43. {
  44.  
  45. throw new ArgumentOutOfRangeException();
  46. }
  47. }
  48. catch (FormatException)
  49. {
  50. Console.WriteLine("Invalid Number!");
  51. }
  52. catch (ArgumentOutOfRangeException)
  53. {
  54. Console.WriteLine($"Your number is not in range {start} - 100!");
  55. }
  56. if (readValue > start && readValue < end)
  57. {
  58. return readValue;
  59. }
  60. return start;
  61.  
  62. }
  63. }
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement