コード例 #1
0
ファイル: Program.cs プロジェクト: rushingfox/DotNetCourse
        static void Main(string[] args)
        {
            L1 :         Console.WriteLine("choose the number:1 for rectangle, 2 for square and 3 for triangle");
            int choice = Convert.ToInt32(Console.ReadLine());

            switch (choice)
            {
            case 1:
                Console.WriteLine("enter the length and width in order:");
                Rectangle shape1 = new Rectangle(Convert.ToDouble(Console.ReadLine()), Convert.ToDouble(Console.ReadLine()));
                if (shape1.legal())
                {
                    Console.WriteLine("legal" + "\n and the area is " + shape1.area_calculating());
                }
                else
                {
                    Console.WriteLine("illegal" + "\n therefore, the area can not be calculated");
                }
                break;

            case 2:
                Console.WriteLine("enter the side_length:");
                Square shape2 = new Square(Convert.ToDouble(Console.ReadLine()));
                if (shape2.legal())
                {
                    Console.WriteLine("legal" + "\n and the area is " + shape2.area_calculating());
                }
                else
                {
                    Console.WriteLine("illegal" + "\n therefore, the area can not be calculated");
                }
                break;

            case 3:
                Console.WriteLine("enter the three sides in order:");
                Triangle shape3 = new Triangle(Convert.ToDouble(Console.ReadLine()), Convert.ToDouble(Console.ReadLine()), Convert.ToDouble(Console.ReadLine()));
                if (shape3.legal())
                {
                    Console.WriteLine("legal" + "\n and the area is " + shape3.area_calculating());
                }
                else
                {
                    Console.WriteLine("illegal" + "\n therefore, the area can not be calculated");
                }
                break;

            default:
                goto L1;
            }

            Console.ReadKey();
        }