コード例 #1
0
        static void Main(string[] args)
        {
            List <double> results = new List <double>();
            string        goagain = "yes";

            while (goagain != "no")
            {
                Console.WriteLine("Please input a value for the left operand. >>");
                double left = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("Please input a value for the right operand. >>");
                double right = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("Which calculation would you like to perform? >> (Add, Subtract, Multiply, Leftpower, Rightpower)");
                string calculation = Console.ReadLine().ToLower();

                Equation eq = new Equation(left, right);

                if (calculation == "add")
                {
                    double add = eq.Add();
                    results.Add(add);
                }
                else if (calculation == "subtract")
                {
                    double subtract = eq.Subtract();
                    results.Add(subtract);
                }
                else if (calculation == "multiply")
                {
                    double multiply = eq.Multiply();
                    results.Add(multiply);
                }
                else if (calculation == "leftpower")
                {
                    Console.WriteLine("To what power would you like to raise the left operand to? >>");
                    int    power     = Convert.ToInt32(Console.ReadLine());
                    double leftpower = eq.LeftToThePower(power);
                    results.Add(leftpower);
                }
                else if (calculation == "rightpower")
                {
                    Console.WriteLine("To what power would you like to raise the right operand to? >>");
                    int    power      = Convert.ToInt32(Console.ReadLine());
                    double rightpower = eq.RightToThePower(power);
                    results.Add(rightpower);
                }
                else
                {
                    Console.WriteLine("Invalid operand");
                    Environment.Exit(0);
                }

                Console.WriteLine("Would you like to perform another calculation? >> (Yes or No)");
                goagain = Console.ReadLine().ToLower();
            }

            foreach (var result in results)
            {
                Console.WriteLine(result.ToString());
            }

            Console.ReadKey();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: kevinhocduong/Exam1Review
        static void Main(string[] args)
        {
            string        answer  = "yes";
            List <string> Results = new List <string>();


            while (answer == "yes" || answer == "y")
            {
                Console.WriteLine("What is your left input?");
                double left = Convert.ToDouble(Console.ReadLine());

                Console.WriteLine("What is your right input?");
                double right = Convert.ToDouble(Console.ReadLine());

                Equation newEquation = new Equation(left, right);

                Console.WriteLine("What type of calculation would you like to run? (+, -, *, power)");
                string calc = Console.ReadLine().ToLower();

                if (calc == "+")
                {
                    Results.Add($"{newEquation.Left} {calc} {newEquation.Right} = {newEquation.Add()}");
                }
                else if (calc == "-")
                {
                    Results.Add($"{newEquation.Left} {calc} {newEquation.Right} = {newEquation.Subtract()}");
                }
                else if (calc == "*")
                {
                    Results.Add($"{newEquation.Left} {calc} {newEquation.Right} = {newEquation.Multiply()}");
                }
                else if (calc == "power")
                {
                    Console.WriteLine("Power to the Left or Right input? (left, right)");
                    string direction = Console.ReadLine().ToLower();

                    Console.WriteLine($"You want to calculate the {direction} input to what power?");
                    int power = Convert.ToInt32(Console.ReadLine());

                    if (direction == "left")
                    {
                        Results.Add($"{newEquation.Left} to the power of {power} is {newEquation.LeftToThePower(power)}");
                    }
                    else if (direction == "right")
                    {
                        Results.Add($"{newEquation.Right} to the power of {power} is {newEquation.RightToThePower(power)}");
                    }
                    else
                    {
                        Console.WriteLine("Error: Please try again.");
                    }
                }
                else
                {
                    Console.WriteLine("Error: Please try again.");
                }

                Console.WriteLine("Would you like to run another equation?");
                answer = Console.ReadLine().ToLower();
            }

            foreach (var result in Results)
            {
                Console.WriteLine(result);
            }

            Console.ReadKey();
        }