Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class ReadNumberMethod
- {
- static void ReadTenNums(int start, int end)
- {
- Console.WriteLine("Enter 10 diferent nums.");
- for (int i = 0; i < 10; i++)
- {
- ReadNumber(start, end);
- }
- }
- static void ReadNumber(int start, int end)
- {
- string input = Console.ReadLine();
- try
- {
- int num = int.Parse(input);
- if (0 < num && num < 100)
- {
- Console.WriteLine("Your number is in range.");
- }
- else
- {
- throw new ArgumentException("Invalide input.");
- }
- }
- catch (FormatException)
- {
- Console.WriteLine("Invalid number.");
- }
- catch (OverflowException)
- {
- Console.WriteLine("Invalid number.");
- }
- catch (ArgumentNullException)
- {
- Console.WriteLine("Invalid number.");
- }
- }
- static void Main()
- {
- int start = 1;
- int end = 100;
- ReadNumber(start, end);
- Console.WriteLine("Check 10 nums:");
- ReadTenNums(start, end);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement