static void Main(string[] args)
        {
            CalculatorClass calc = new CalculatorClass();

            Console.WriteLine("Testing Addition - calc.Add(x,x)");
            Console.WriteLine($"8 + 2 = {calc.Add(8, 2)}");
            Console.WriteLine($"909 + 525 = {calc.Add(909, 525)}");
            Console.WriteLine($"352 + 86 = {calc.Add(352, 86)}");
            Console.WriteLine($"155 + 35 = {calc.Add(155, 35)}\n");


            Console.WriteLine("Testing Subtract - calc.Subtract(x,x)");
            Console.WriteLine($"8 - 2 = {calc.Subtract(8, 2)}");
            Console.WriteLine($"55 - 5 = {calc.Subtract(55, 5)}");
            Console.WriteLine($"25 - 86 = {calc.Subtract(25, 86)}");
            Console.WriteLine($"155 - 5 = {calc.Subtract(155, 5)}\n");


            Console.WriteLine("Testing Multiply - calc.Multiply(x,x)");
            Console.WriteLine($"8 * 2 = {calc.Multiply(8, 2)}");
            Console.WriteLine($"9 * 5 = {calc.Multiply(9, 5)}");
            Console.WriteLine($"2 * 86 = {calc.Multiply(2, 86)}");
            Console.WriteLine($"54 * 5 = {calc.Multiply(54, 5)}\n");


            Console.WriteLine("Testing Power - calc.Power(x,x)");
            Console.WriteLine($"5 power 2 = {calc.Power(5, 2)}");
            Console.WriteLine($"25 power 4 = {calc.Power(25, 4)}");
            Console.WriteLine($"25 power 6 = {calc.Power(25, 6)}");
            Console.WriteLine($"14 power 2 = {calc.Power(14, 2)}\n");
        }
Esempio n. 2
0
        private void Button_equal_Click(object sender, RoutedEventArgs e)
        {
            OperationsHistory.Text = Output.Text + "=";
            Output.Text            = CalculatorClass.Calculate(Output.Text).ToString();

            equalPressed = true;
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            CalculatorClass calc      = new CalculatorClass();
            int             sumResult = calc.Sum(2, 4);

            Console.WriteLine(sumResult);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            CalculatorClass calc = new CalculatorClass();

            Console.WriteLine($"2+7 = {calc.Add(2, 7)}");
            Console.WriteLine($"12-2 = {calc.Subtract(12, 2)}");
            Console.WriteLine($"4*5 = {calc.Multiply(4, 5)}");
            Console.WriteLine($"5^3 = {calc.Power(5, -3)}");
        }
Esempio n. 5
0
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                OperationsHistory.Text = Output.Text + "=";
                Output.Text            = CalculatorClass.Calculate(Output.Text).ToString();

                equalPressed = true;
            }

            if (e.Key == Key.Back)
            {
                if (Output.Text.Length > 0)
                {
                    Output.Text = Output.Text.Substring(0, Output.Text.Length - 1);
                }
            }
        }
Esempio n. 6
0
        //BUTTONS:

        //addition
        private void buttonPlus_Click(object sender, EventArgs e)
        {
            CalculatorClass calc = new CalculatorClass();

            try
            {
                double d = double.Parse(textBoxA.Text);
                double c = double.Parse(textBoxB.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Wrong input! Reload the calculator and try again! For instructions, open ReadMe.txt in the programme files.");
                Application.Exit();
            }

            double a = double.Parse(textBoxA.Text);
            double b = double.Parse(textBoxB.Text);

            LabelResult.Visible = true;
            LabelResult.Text    = $"{a + b}";
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string content = (string)(sender is Button ? ((Button)sender).Content : sender);

            switch (content)
            {
            case "+": calculationTypeChosen = CalculationType.Add; break;

            case "-": calculationTypeChosen = CalculationType.Subtract; break;

            case "/": calculationTypeChosen = CalculationType.Divide; break;

            case "x": calculationTypeChosen = CalculationType.Multiply; break;

            case "c":
                inputs = new string[2];
                calculationTypeChosen = null;
                showingResult         = false;
                InputDisplay.Content  = "";
                break;

            case "=":
                if (calculationTypeChosen == null)
                {
                    return;
                }
                InputDisplay.Content = CalculatorClass.Calculate(Convert.ToDouble(inputs[0], cultureInfo), Convert.ToDouble(inputs[1], cultureInfo), calculationTypeChosen);
                showingResult        = true;
                break;

            default:
                if (showingResult)
                {
                    Button_Click("c", new RoutedEventArgs());
                }
                inputs[calculationTypeChosen != null ? 1 : 0] += content;
                InputDisplay.Content = inputs[calculationTypeChosen != null ? 1 : 0];
                break;
            }
        }
Esempio n. 8
0
 public void Initialize()
 {
     calculator = new CalculatorClass();
 }
Esempio n. 9
0
 public Calculator()
 {
     InitializeComponent();
     calculator = new CalculatorClass();
 }
Esempio n. 10
0
 public Calculator()
 {
     InitializeComponent();
     calculator = new CalculatorClass();
 }
Esempio n. 11
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the calculator!");

            CalculatorClass Calculator = new CalculatorClass();

            while (true)
            {
                Console.WriteLine("Choose operation:");
                Console.WriteLine("1: Add");
                Console.WriteLine("2: Subtract");
                Console.WriteLine("3: Multiply");
                Console.WriteLine("4: Divide");
                Console.WriteLine("5: Power");

                double switchVar = Convert.ToDouble(Console.ReadLine());

                Console.WriteLine("First number:");
                double a = Convert.ToDouble(Console.ReadLine());

                Console.WriteLine("Second number:");
                double b = Convert.ToDouble(Console.ReadLine());

                double result;

                switch (switchVar)
                {
                case 1:
                    result = Calculator.Add(a, b);
                    break;

                case 2:
                    result = Calculator.Subtract(a, b);
                    break;

                case 3:
                    result = Calculator.Multiply(a, b);
                    break;

                case 4:
                    try
                    {
                        result = Calculator.Divide(a, b);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                    finally
                    {
                        result = 0;
                    }
                    break;

                case 5:
                    result = Calculator.Power(a, b);
                    break;

                default:
                    result = 0;
                    break;
                }

                Console.WriteLine("Result: " + result);
                Console.WriteLine();
            }
        }