Advertisement
Guest User

Untitled

a guest
May 29th, 2015
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 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. if (array[i] <= start)
  21. {
  22. Console.WriteLine("The number must be > that {0} and < than 100", start);
  23. i--;
  24. continue;
  25. }
  26. start = array[i];
  27. //start = ReadNumber(start, end);
  28.  
  29. }
  30.  
  31. foreach (var num in array)
  32. {
  33. Console.Write("Your numbers are {0}", num);
  34. }
  35.  
  36.  
  37.  
  38. }
  39.  
  40. public static int ReadNumber(int start, int end)
  41. {
  42.  
  43. int num = 0;
  44.  
  45.  
  46. try
  47. {
  48. num = Int32.Parse(Console.ReadLine());
  49.  
  50. if (num < 0 || num > 100)
  51. {
  52. throw new ArgumentOutOfRangeException();
  53. }
  54.  
  55. }
  56. catch(FormatException)
  57. {
  58. Console.WriteLine("Please enter a number");
  59. ReadNumber(start, end);
  60. }
  61. catch(ArgumentOutOfRangeException)
  62. {
  63. Console.WriteLine("Please enter a number between {0} and {1}",start, end);
  64. ReadNumber(start, end);
  65. }
  66.  
  67. return num;
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement