static void Main(string[] args)
        {
            Console.WriteLine("Press enter to begin");

            String restart = Console.ReadLine();

            do
            {
                try
                {
                    //Class to convert user input
                    InputConverter inputConverter = new InputConverter();

                    //Class to perform actual calculations
                    CalculatorEngine calculatorEngine = new CalculatorEngine();

                    Console.WriteLine("Please enter the first number:");
                    double firstNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                    while (double.IsNaN(firstNumber))
                    {
                        firstNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                    }

                    Console.WriteLine("Please enter the second number:");
                    double secondNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                    while (double.IsNaN(secondNumber))
                    {
                        secondNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                    }

                    Console.WriteLine("Please enter the operator:");
                    string operation = Console.ReadLine();

                    double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber);
                    while (double.IsNaN(result))
                    {
                        Console.WriteLine("Invalid operator \nPlease utilize one of the following: \nadd subtract multiply divide + - * / \n");
                        operation = Console.ReadLine();
                        result    = calculatorEngine.Calculate(operation, firstNumber, secondNumber);
                    }

                    Console.WriteLine("The value " + String.Format("{0:.00}", firstNumber) + " " + operation + " " + String.Format("{0:.00}", secondNumber) + " is equal to " + String.Format("{0:.00}", result));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Console.WriteLine("Would you like to restart application. if yes, write 'yes'");
                restart = Console.ReadLine();
            } while (restart == "yes");
            System.Environment.Exit(0);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            InputConverter   inputConventer   = new InputConverter();
            CalculatorEngine calculatorEngine = new CalculatorEngine();

            double firstNumber  = InputConverter.ConvertInputToNumber(Console.ReadLine());
            double secondNumber = InputConverter.ConvertInputToNumber(Console.ReadLine());
            string operation    = Console.ReadLine();

            double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber);

            Console.WriteLine(result);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            try
            {
                //Class to convert user input
                InputConverter inputConverter = new InputConverter();

                //Class to perform actual calculations
                CalculatorEngine calculatorEngine = new CalculatorEngine();
         

                double firstNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                double secondNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                string operation = Console.ReadLine();
Beispiel #4
0
        public CalcUI()
        {
            //
            // Required for Windows Form Designer support
            //

            InitializeComponent();

            //
            // Get version information from the Calculator Module.
            //

            VersionInfo.Text   = CalculatorEngine.GetVersion();
            OutputDisplay.Text = "0";
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            bool Decision = true;  //Variable declared for Re-executing the code from users choice

            do
            {
                try
                {
                    var inputConverter   = new InputConverter();
                    var calculatorEngine = new CalculatorEngine();
                    Console.WriteLine(@"               Operation Guide
                        1.Addition-> 'add' or '+'
                        2.Subtraction-> 'subtract' or '-'
                        3.Multiplication-> 'multiply' or '*'
                        4.Division-> 'divide' or '/'
");
                    Console.WriteLine("Enter First Number:");
                    double firstNumber = inputConverter.ConvertInputToNumber(Console.ReadLine());  //Input 1
                    Console.WriteLine("Enter Second Number:");
                    double secondNumber = inputConverter.ConvertInputToNumber(Console.ReadLine()); //Input 2
                    Console.WriteLine("Enter Operation from above specified:");
                    string operation = Console.ReadLine();                                         //Operation (+,-,*,/)
                    Console.WriteLine("----------Result----------");
                    double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber);

                    Console.WriteLine(result);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                //For Re-executing the code from users choice
                var continueProgram = string.Empty;
                Console.WriteLine();
                do
                {
                    Console.WriteLine("Do You Want To Continue? Y/N");
                    continueProgram = (Console.ReadLine() ?? string.Empty);
                } while (!continueProgram.Equals("Y", StringComparison.OrdinalIgnoreCase) &&
                         !continueProgram.Equals("N", StringComparison.OrdinalIgnoreCase));


                Decision = continueProgram.Equals("Y", StringComparison.OrdinalIgnoreCase);
            } while (Decision);
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            InputConverter   inputConverter   = new InputConverter();
            CalculatorEngine calculatorEngine = new CalculatorEngine();

            Console.WriteLine("Please enter your first number");
            double firstNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());

            Console.WriteLine("Please enter your second number");
            double secondNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());

            Console.WriteLine("Please enter the operation");
            string operation = Console.ReadLine();

            double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber);

            Console.WriteLine($"Your answer is: {result}");
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            try
            {
                InputConverter   inputConverter   = new InputConverter();
                CalculatorEngine calculatorEngine = new CalculatorEngine();

                double firstNumber  = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                double secondNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                string operation    = Console.ReadLine();

                double result = calculatorEngine.Calculate(firstNumber, secondNumber, operation);
                Console.WriteLine(result);
            } catch (Exception ex)
            {
                // TODO: Start logging exceptions.
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            try
            {
                InputConverter   inputConverter   = new InputConverter();
                CalculatorEngine calculatorEngine = new CalculatorEngine();

                double firstNumber  = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                double secondNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                string operation    = Console.ReadLine();

                double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber);

                Console.WriteLine(result);
            } catch (Exception ex) {
                //in the real world, we would want to log this message.
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            bool   continueProgram = true;
            string strRestart;

            do
            {
                try
                {
                    InputConverter   inputConverter   = new InputConverter();
                    CalculatorEngine calculatorEngine = new CalculatorEngine();

                    // Prompt for and receive equation
                    Console.Write(Constants.PromptForFirstNumber);
                    double dblNum1 = inputConverter.ConvertToNumeric(Console.ReadLine());
                    Console.Write(Constants.PromptForSecondNumber);
                    double dblNum2 = inputConverter.ConvertToNumeric(Console.ReadLine());
                    Console.Write(Constants.PromptForOperator);
                    string operation = Console.ReadLine();

                    // Call Calculate function
                    double result = calculatorEngine.Calculate(operation, dblNum1, dblNum2);

                    // Write result
                    Console.WriteLine(result);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    // Ask if user wants to restart program
                    do
                    {
                        Console.Write(Constants.PromptForRestartingProgram);
                        strRestart = Console.ReadLine();
                    } while (!strRestart.Equals(Constants.InputToRestartProgram, StringComparison.OrdinalIgnoreCase) && !strRestart.Equals(Constants.InputToStopProgram, StringComparison.OrdinalIgnoreCase));
                    // Set boolean based on user's input
                    continueProgram = strRestart.Equals(Constants.InputToRestartProgram, StringComparison.OrdinalIgnoreCase);
                }
            } while (continueProgram);
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            try {
                InputConverter   inputConverter   = new InputConverter();
                CalculatorEngine calculatorEngine = new CalculatorEngine();

                double FirstNumber  = inputConverter.ConvetInputToNumeric(Console.ReadLine());
                double SecondNumber = inputConverter.ConvetInputToNumeric(Console.ReadLine());

                string operation = Console.ReadLine();

                double result = calculatorEngine.calculate(operation, FirstNumber, SecondNumber);
                Console.WriteLine(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            try
            {
                InputConverter   inputConverter   = new InputConverter();
                CalculatorEngine calculatorEngine = new CalculatorEngine();

                double firstNumber  = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                double secondNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                string operation    = Console.ReadLine();

                double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber);

                Console.WriteLine(result);
            }

            catch (Exception ex)
            {
                Console.WriteLine("There was an error: {0}", ex.Message);
            }
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            try
            {
                InputConvertor   inputConvertor   = new InputConvertor();
                CalculatorEngine calculatorEngine = new CalculatorEngine();

                double firstNumber  = inputConvertor.ConvertInputToNumeric(Console.ReadLine());
                double secondNumber = inputConvertor.ConvertInputToNumeric(Console.ReadLine());
                string operation    = Console.ReadLine();

                double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber);

                Console.WriteLine(result);
            }
            catch (Exception ex)
            {
                //In real time application we log exception into log file
                Console.WriteLine(ex.Message);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                //Class to convert user input
                InputConverter inputConverter = new InputConverter();

                //Class to perform actual calculations
                CalculatorEngine calculatorEngine = new CalculatorEngine();

                double firstNumber  = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                double secondNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                string operation    = Console.ReadLine();

                double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber);

                Console.WriteLine(result);
            } catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        static void Main(string[] args)
        {
            int num = 0;
            int a   = 0;

            do
            {
                try
                {
                    if (a == 0)
                    {
                        Console.WriteLine("to exit type meme for the operator.");
                        a++;
                    }

                    //Class to convert user input
                    InputConverter inputConverter = new InputConverter();

                    //Class to perform actual calculations
                    CalculatorEngine calculatorEngine = new CalculatorEngine();

                    double firstNumber  = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                    double secondNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                    string operation    = Console.ReadLine();
                    if (operation == "meme")
                    {
                        num = num + 5;
                    }

                    double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber);

                    Console.WriteLine(result);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }while (num < 1);
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            try
            {
                InputConverter   inputConverter   = new InputConverter();
                CalculatorEngine calculatorEngine = new CalculatorEngine();

                double firstNumber  = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                string operation    = Console.ReadLine();
                double secondNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                double result       = calculatorEngine.Calculate(operation, firstNumber, secondNumber);

                Console.WriteLine(result);
                Console.WriteLine("");
                Console.WriteLine("Press any key to exit the application");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                // TODO: start logging exceptions
                Console.WriteLine(ex.Message);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                InputConverter   inputConverter   = new InputConverter();
                CalculatorEngine calculatorEngine = new CalculatorEngine();

                Console.WriteLine("Enter first number");
                double firstNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                Console.WriteLine("Enter second number");
                double secondNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                Console.WriteLine("Enter operation to calculate");
                string operation = Console.ReadLine();

                double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber);

                Console.WriteLine("Result = " + result);
            }
            catch (Exception ex)
            {
                //In real world we log the message
                Console.WriteLine("Error : " + ex.Message);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                // Instantiating usable classes
                InputConverter   inputConverter   = new InputConverter();
                CalculatorEngine calculatorEngine = new CalculatorEngine();

                // Getting input data
                double firstNumber  = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                double secondNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                string operation    = Console.ReadLine();

                // Calculating operation
                double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber);

                // Printing result
                Console.WriteLine(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #18
0
 protected void KeyPoint_Click(object sender, System.EventArgs e)
 {
     OutputDisplay.Text = CalculatorEngine.CalcDecimal();
 }
Beispiel #19
0
 protected void KeyDivide_Click(object sender, System.EventArgs e)
 {
     CalculatorEngine.CalcOperation(CalculatorEngine.Operator.eDivide);
 }
        static void Main(string[] args)
        {
            int num = 0;
            int a = 0;
            do
                //Console.WriteLine("TEST");
                try
            {
                    if (a == 0) {
                        Console.WriteLine("to exit type meme for the operator.");
                        a++;
                    }
                    //Class to convert user input
                    InputConverter inputConverter = new InputConverter();

                //Class to perform actual calculations
                CalculatorEngine calculatorEngine = new CalculatorEngine();

                double firstNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                double secondNumber = inputConverter.ConvertInputToNumeric(Console.ReadLine());
                string operation = Console.ReadLine();

                    if (operation == "meme")
                    {
                        num = num + 5;
                    }

                    double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber);

                string operationText;
                operationText = "empty";
                if (operation == "+")
                {
                    operationText = "plus";
                }
                if (operation == "-")
                {
                    operationText = "minus";
                }
                if (operation == "*")
                {
                    operationText = "times";
                }
                if (operation == "^")
                {
                    operationText = "exponent";
                }
                    if (operation == "/")
                {
                    operationText = "divides";
                }

                    if (result == 420 || result == 69)
                    {
                        Console.WriteLine("nice");
                    }
                    else
                    {
                        Console.WriteLine("The value" + " " + firstNumber + " " + operationText + " " + secondNumber + " " + "equals" + " " + Math.Round(result, 2));
                    }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            while (num < 1);
        }
Beispiel #21
0
 private void KeySquaring_Click(object sender, EventArgs e)
 {
     CalculatorEngine.CalcOperation(CalculatorEngine.Operator.eSquaring);
 }
Beispiel #22
0
 private void KeyReverse_Click(object sender, EventArgs e)
 {
     CalculatorEngine.CalcOperation(CalculatorEngine.Operator.eReverse);
 }
Beispiel #23
0
 private void KeyCubeRoot_Click(object sender, EventArgs e)
 {
     CalculatorEngine.CalcOperation(CalculatorEngine.Operator.eCubeRoot);
 }
Beispiel #24
0
 private void KeyFactorial_Click(object sender, EventArgs e)
 {
     CalculatorEngine.CalcOperation(CalculatorEngine.Operator.eFactorial);
 }
Beispiel #25
0
 protected void KeyZero_Click(object sender, System.EventArgs e)
 {
     OutputDisplay.Text = CalculatorEngine.CalcNumber(zeroOut);
 }
Beispiel #26
0
        //
        // Perform the calculation.
        //

        protected void KeyEqual_Click(object sender, System.EventArgs e)
        {
            OutputDisplay.Text = CalculatorEngine.CalcEqual();
            CalculatorEngine.CalcReset();
        }
Beispiel #27
0
 protected void clearToolStripMenuItem_Click(object sender, EventArgs e)
 {
     CalculatorEngine.CalcReset();
     OutputDisplay.Text = "0";
 }
Beispiel #28
0
        //
        // Other non-numeric key click methods.
        //

        protected void KeySign_Click(object sender, System.EventArgs e)
        {
            OutputDisplay.Text = CalculatorEngine.CalcSign();
        }
Beispiel #29
0
        static void Main(string[] args)
        {
            try
            {
                //Class to convert user input
                InputConverter inputConverter = new InputConverter();

                //Class to perform actual calculations
                CalculatorEngine calculatorEngine = new CalculatorEngine();

                bool   isDigit      = false;
                double firstNumber  = 0;
                double secondNumber = 0;

                while (!isDigit)
                {
                    Console.WriteLine("Enter your first number: ");
                    string sRes = Console.ReadLine();

                    isDigit = Double.TryParse(sRes, out firstNumber);

                    if (isDigit)
                    {
                        break;
                    }
                }
                isDigit = false;
                while (!isDigit)
                {
                    Console.WriteLine("Enter your second number: ");
                    string sRes = Console.ReadLine();

                    isDigit = Double.TryParse(sRes, out secondNumber);

                    if (isDigit)
                    {
                        break;
                    }
                }

                bool   isOperation = false;
                string operation   = " ";
                while (!isOperation)
                {
                    Console.WriteLine("Enter your desired operation out of the following: add or +, subtract or -, divide or /, multiply or * and power or ^ :");
                    operation = Console.ReadLine().ToLower();

                    isOperation = ((operation == "add") || (operation == "+") || (operation == "subtract") || (operation == "-") ||
                                   (operation == "multiply") || (operation == "*") || (operation == "divide") || (operation == "/") ||
                                   (operation == "power") || (operation == "^"));

                    if (isOperation)
                    {
                        break;
                    }
                }
                Console.WriteLine("Enter your desired operation out of the following: add or +, subtract or -, divide or /, multiply or * and power or ^ :");
                operation = Console.ReadLine().ToLower();


                double result = calculatorEngine.Calculate(operation, firstNumber, secondNumber);

                Console.WriteLine(result);
                StringBuilder sb = new StringBuilder();
                sb.Append("Your first number ");
                sb.Append(firstNumber);
                switch (operation)
                {
                case "add":
                case "+":
                    sb.Append(" plus ");
                    break;

                case "subtract":
                case "-":
                    sb.Append(" minus ");
                    break;

                case "multiply":
                case "*":
                    sb.Append(" times ");
                    break;

                case "division":
                case "/":
                    sb.Append(" divided by ");
                    break;

                case "power":
                case "^":
                    sb.Append(" to the power of ");
                    break;
                }
                sb.Append("your second number ");
                sb.Append(secondNumber);
                sb.Append(" equals to ");
                sb.Append(result);

                Console.WriteLine(sb.ToString());
                Console.ReadLine();

                System.IO.File.WriteAllText(@"C:\Users\Public\Documents\CalcResult.txt", sb.ToString());
            } catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #30
0
 protected void KeyClear_Click(object sender, System.EventArgs e)
 {
     CalculatorEngine.CalcReset();
     OutputDisplay.Text = "0";
 }