예제 #1
0
        static void Main(string[] args)
        {
            int    value;
            double choice;

            do
            {
                Console.Write("(1) Cicle (2) Square (3) Exit: ");
                value = Int32.Parse(Console.ReadLine());
                Console.Clear();

                if (value == 1)
                {
                    Console.Write("(1) Area (2) Radius: ");
                    choice = Double.Parse(Console.ReadLine());

                    if (choice == 1)
                    {
                        Console.Write("Enter radius: ");
                        Console.WriteLine(Circle.GetCircleArea(Double.Parse(Console.ReadLine())));
                    }
                    else if (choice == 2)
                    {
                        Console.Write("Enter area: ");
                        Console.WriteLine(Circle.GetCircleValues(Double.Parse(Console.ReadLine())));
                    }
                }
                else if (value == 2)
                {
                    Console.Write("(1) Area (2) Width: ");
                    choice = Double.Parse(Console.ReadLine());

                    if (choice == 1)
                    {
                        Console.Write("Enter width: ");
                        Console.WriteLine(Square.GetSquareArea(Double.Parse(Console.ReadLine())));
                    }
                    else if (choice == 2)
                    {
                        Console.Write("Enter area: ");
                        Console.WriteLine(Square.GetSquareValues(Double.Parse(Console.ReadLine())));
                    }
                }
            }while (value != 3);
        }
예제 #2
0
        static void Main(string[] args)
        {
            //Takes in the users input
            int input = 0;

            //Loop untill user input 1 of the 3 options
            while (input != 3)
            {
                Console.Clear();//Clears the screen
                Console.WriteLine("Please choose from the following options:");
                Console.WriteLine("Press 1 to find the area of a circle.");
                Console.WriteLine("Press 2 to find the area of a square.");
                Console.WriteLine("Press 3 to exit.");
                //Checks if its a valid input
                bool check = int.TryParse(Console.ReadLine(), out input);
                if (!check)
                {
                    while (!check)       //loops until a number is input
                    {
                        Console.Clear(); //Clears the screen.
                        Console.WriteLine("There was a problem with your input, please try again. ");
                        Console.WriteLine("Press 1 to find the area of a circle.");
                        Console.WriteLine("Press 2 to find the area of a square.");
                        Console.WriteLine("Press 3 to exit.");
                        check = int.TryParse(Console.ReadLine(), out input);
                    }
                }
                //Call the Circle class and methods
                if (input == 1)
                {
                    Circle.GetCircleValues();
                }
                //Call the Square class and methods
                else if (input == 2)
                {
                    Square.GetSquareValues();
                }
                //Exit
                else if (input == 3)
                {
                    break;
                }
            }
        }