Esempio n. 1
0
    static void Main()
    {
        UserDefException objEx = new UserDefException();

        try {
            int[]  marks1 = new int[3];
            int[]  marks2 = new int[3];
            string student1, student2;
            Console.Write("Enter the name of student 1 : ");
            student1 = Console.ReadLine();
            Console.WriteLine("Enter their marks below : ");
            for (int i = 0; i < 3; i++)
            {
                Console.Write("Mark for subject {0} : ", (i + 1));
                marks1[i] = Int32.Parse(Console.ReadLine());
                objEx.validate(marks1[i]);
            }
            Console.WriteLine();
            Console.Write("Enter the name of student 2 : ");
            student2 = Console.ReadLine();
            Console.WriteLine("Enter their marks below : ");
            for (int i = 0; i < 3; i++)
            {
                Console.Write("Mark for subject {0} : ", (i + 1));
                marks2[i] = Int32.Parse(Console.ReadLine());
                objEx.validate(marks2[i]);
            }
            Console.WriteLine();
            Console.WriteLine("Average marks of {0}", student1);
            findAverage(marks1);
            Console.WriteLine();
            Console.WriteLine("Average marks of {0}", student2);
            findAverage(marks2);
        }
        catch (NegativeMarksException e)
        {
            Console.WriteLine(e);
        }
        catch (OutOfRangeException e)
        {
            Console.WriteLine(e);
        }
        catch (FormatException)
        {
            Console.WriteLine("Invalid input");
        }
        Console.ReadKey();
    }
Esempio n. 2
0
    static void Main()
    {
        try
        {
            int inputNo;
            Console.Write("Enter an integer (between 1-365) : ");
            inputNo = Int32.Parse(Console.ReadLine());
            UserDefException objEx = new UserDefException();
            objEx.validate(inputNo);

            string month, output;
            if (inputNo >= 1 && inputNo <= 31)
            {
                month  = "January";
                output = month + " " + Convert.ToString(inputNo);
                Console.WriteLine(output);
            }
            else if (inputNo > 31 && inputNo <= 59)
            {
                month  = "February";
                output = month + " " + Convert.ToString(Math.Abs(31 - inputNo));
                Console.WriteLine(output);
            }
            else if (inputNo > 59 && inputNo <= 90)
            {
                month  = "March";
                output = month + " " + Convert.ToString(Math.Abs(59 - inputNo));
                Console.WriteLine(output);
            }
            else if (inputNo > 90 && inputNo <= 120)
            {
                month  = "April";
                output = month + " " + Convert.ToString(Math.Abs(90 - inputNo));
                Console.WriteLine(output);
            }
            else if (inputNo > 120 && inputNo <= 151)
            {
                month  = "May";
                output = month + " " + Convert.ToString(Math.Abs(120 - inputNo));
                Console.WriteLine(output);
            }
            else if (inputNo > 151 && inputNo <= 181)
            {
                month  = "June";
                output = month + " " + Convert.ToString(Math.Abs(151 - inputNo));
                Console.WriteLine(output);
            }
            else if (inputNo > 181 && inputNo <= 212)
            {
                month  = "July";
                output = month + " " + Convert.ToString(Math.Abs(181 - inputNo));
                Console.WriteLine(output);
            }
            else if (inputNo > 212 && inputNo <= 243)
            {
                month  = "August";
                output = month + " " + Convert.ToString(Math.Abs(212 - inputNo));
                Console.WriteLine(output);
            }
            else if (inputNo > 243 && inputNo <= 273)
            {
                month  = "September";
                output = month + " " + Convert.ToString(Math.Abs(243 - inputNo));
                Console.WriteLine(output);
            }
            else if (inputNo > 273 && inputNo <= 304)
            {
                month  = "October";
                output = month + " " + Convert.ToString(Math.Abs(273 - inputNo));
                Console.WriteLine(output);
            }
            else if (inputNo > 304 && inputNo <= 334)
            {
                month  = "November";
                output = month + " " + Convert.ToString(Math.Abs(304 - inputNo));
                Console.WriteLine(output);
            }
            else if (inputNo > 334 && inputNo <= 365)
            {
                month  = "December";
                output = month + " " + Convert.ToString(Math.Abs(334 - inputNo));
                Console.WriteLine(output);
            }
        }
        catch (InvalidArgument e)
        {
            Console.WriteLine(e);
        }
        Console.ReadKey();
    }