Beispiel #1
0
 private void Equals_Click(object sender, RoutedEventArgs e)
 {
     if (MemoryTextField.Text != "" && CurrentNumberTextField.Text != "" && !IsLastButtonEquals)
     {
         MemoryTextField.Text       += CurrentNumberTextField.Text;
         CurrentNumberTextField.Text = MathematicalBackground.PerformCalculations(MemoryTextField.Text).ToString();
         IsLastButtonEquals          = true;
     }
 }
Beispiel #2
0
        private void Function_1_Argument_Click(object sender, RoutedEventArgs e)
        {
            ClearMemoryTextField();
            Button button    = (Button)sender;
            string operation = button.Content.ToString();

            if (CurrentNumberTextField.Text != "")
            {
                CurrentNumberTextField.Text = MathematicalBackground.Perform1ArgumentFunction(CurrentNumberTextField.Text, operation).ToString();
                IsLastButton1ArgFunction    = true;
            }
        }
Beispiel #3
0
        public static double PerformCalculations(string calculations)
        {
            string[]      values     = calculations.Split();
            List <double> numbers    = new List <double>();
            List <string> operations = new List <string>();

            for (int i = 0; i < values.Length; i += 2)
            {
                numbers.Add(Convert.ToDouble(values[i]));
            }
            for (int i = 1; i < values.Length; i += 2)
            {
                operations.Add(values[i]);
            }
            for (int i = 0; i < operations.Count; i++)
            {
                numbers[i + 1] = MathematicalBackground.Calculate(numbers[i], operations[i], numbers[i + 1]);
            }
            return(numbers[numbers.Count - 1]);
        }