Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _02.EnterNumbers
- {
- class Program
- {
- static void Main()
- {
- int start = 1;
- int end = 100;
- int[] array = new int[10];
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = ReadNumber(start, end);
- if (array[i] <= start)
- {
- Console.WriteLine("The number must be > that {0} and < than 100", start);
- i--;
- continue;
- }
- start = array[i];
- //start = ReadNumber(start, end);
- }
- foreach (var num in array)
- {
- Console.Write("Your numbers are {0}", num);
- }
- }
- public static int ReadNumber(int start, int end)
- {
- int num = 0;
- try
- {
- num = Int32.Parse(Console.ReadLine());
- if (num < 0 || num > 100)
- {
- throw new ArgumentOutOfRangeException();
- }
- }
- catch(FormatException)
- {
- Console.WriteLine("Please enter a number");
- ReadNumber(start, end);
- }
- catch(ArgumentOutOfRangeException)
- {
- Console.WriteLine("Please enter a number between {0} and {1}",start, end);
- ReadNumber(start, end);
- }
- return num;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement