コード例 #1
0
        static void Main(string[] args)
        {
            int  myInt = 0;
            bool run   = true;

            Console.WriteLine("Welcome to the Factorial Calculator!");
            while (run)
            {
                myInt = IntValidator.getIntWithinRange("", 0, 20);
                long factorial = CalculateFactorial(myInt);
                Console.WriteLine("\nThe factorial of " + myInt + " is " + factorial + ".");
                run = Continue();
            }
            Console.ReadLine();
        }
コード例 #2
0
        //For the user to proceed, he or she must enter an integer within the specified range.

        public static int getIntWithinRange(string prompt, int min, int max)
        {
            bool         run = true;
            IntValidator num = new IntValidator();

            while (run)
            {
                Console.Write("\nEnter an integer between " + min + " and " + max + ":");
                _myInt = IntValidator.getInt(Console.ReadLine());
                if (_myInt < min)
                {
                    Console.WriteLine("\nError! Please enter an integer greater than " + (min - 1));
                }
                else if (_myInt > max)
                {
                    Console.WriteLine("\nError! Please enter an integer less than " + (max + 1));
                }
                else
                {
                    run = false;
                }
            }
            return(_myInt);
        }