Advertisement
Guest User

Untitled

a guest
May 29th, 2015
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _02.EnterNumbers
  8. {
  9. class Program
  10. {
  11. static void Main()
  12. {
  13. int start = 1;
  14. int end = 100;
  15. int[] array = new int[10];
  16. for (int i = 0; i < array.Length; i++)
  17. {
  18.  
  19. //array[i] = ReadNumber(start, end);
  20.  
  21. try
  22. {
  23. array[i] = ReadNumber(start, end);
  24.  
  25.  
  26. if (array[i] <= start || array[i] > 100)
  27. {
  28. throw new ArgumentOutOfRangeException();
  29. }
  30. }
  31. catch (FormatException)
  32. {
  33. Console.WriteLine("Please enter a valid number");
  34. i--;
  35. continue;
  36. }
  37. catch (ArgumentOutOfRangeException)
  38. {
  39. Console.WriteLine("Number must be bigger than {0} and smaller than {1}!",start, end);
  40. i--;
  41. continue;
  42. }
  43.  
  44.  
  45. start = array[i];
  46. }
  47.  
  48. Console.Write("Your numbers are: ");
  49. foreach (var n in array)
  50. {
  51. Console.Write(n + ", ");
  52. }
  53. Console.WriteLine();
  54.  
  55. }
  56. public static int ReadNumber(int start, int end)
  57. {
  58. string input = Console.ReadLine();
  59. int num;
  60. while (!int.TryParse(input, out num))
  61. {
  62. throw new FormatException();
  63. }
  64.  
  65.  
  66. return num;
  67. }
  68.  
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement