static void restart() { int a, b; string o; operators(out o); Firstnumber(out a); Secondnumber(out b); if (o == "+") { operations p1 = new operations(); float Ans = p1.add(a, b); Console.WriteLine($"Addition of {a} and {b} is = " + Ans); Console.WriteLine("Type 'y' if you want to continue your calculation or Double press Enter to Exit "); string input = Console.ReadLine(); if (input == "y") { restart(); } } if (o == "-") { operations p1 = new operations(); float Ans = p1.sub(a, b); Console.WriteLine($"Subtraction of {a} and {b} is = " + Ans); Console.WriteLine("Type 'y' if you want to continue your calculation or Double press Enter to Exit "); string input = Console.ReadLine(); if (input == "y") { restart(); } } if (o == "*") { operations p1 = new operations(); float Ans = p1.multiplication(a, b); Console.WriteLine($"Multiplication of {a} and {b} is = " + Ans); Console.WriteLine("Type 'y' if you want to continue your calculation or Double press Enter to Exit "); string input = Console.ReadLine(); if (input == "y") { restart(); } } if (o == "/") { operations p1 = new operations(); float Ans = p1.division(a, b); Console.WriteLine($"Division of {a} and {b} is = " + Ans); Console.WriteLine("Type 'y' if you want to continue your calculation or Double press Enter to Exit "); string input = Console.ReadLine(); if (input == "y") { restart(); } } }
/// <summary> /// Displays the given text in the result box. /// </summary> private void showError(string text) { resultBox.Text = text; previousText = null; operationCheck = false; clearNext = true; updateEquationBox(""); currentOperation = operations.NULL; resetFontSize(); }
/// <summary> /// Deals with double operand function clicks. /// </summary> private void doubleOperandFunction(object sender, RoutedEventArgs e) { if (errors.Contains(resultBox.Text)) { return; } if (operationCheck && !isOldText) { calculateResult(); } Button button = (Button)sender; operationCheck = true; previousText = resultBox.Text; string buttonText = button.Content.ToString(); string equation = previousText + " " + buttonText + " "; switch (buttonText) { case "/": currentOperation = operations.DIVISION; break; case "x": currentOperation = operations.MULTIPLICATION; break; case "-": currentOperation = operations.SUBTRACTION; break; case "+": currentOperation = operations.ADDITION; break; case "^": currentOperation = operations.POWER; break; } updateEquationBox(equation); resetFontSize(); showText(resultBox.Text); isOldText = true; }
private void BEquals_Click(object sender, RoutedEventArgs e) { switch (operation) { case operations.plus: { m_data.total += temptotal; temptotal = 0; sign = 1; operation = operations.idle; break; } case operations.minus: { m_data.total = (temptotal - m_data.total); temptotal = 0; sign = 1; operation = operations.idle; break; } case operations.multiply: { m_data.total *= temptotal; temptotal = 0; sign = 1; operation = operations.idle; break; } case operations.divide: { m_data.total = (temptotal / m_data.total); temptotal = 0; sign = 1; operation = operations.idle; break; } default: break; } }
public void Plus(Calculator.operations operation) { if (text.Length > 1 || !operation_last_symbol) { if (operation_last_symbol) { base.Backspace(); } Plus(Calculator.Operation(operation)); operation_last_symbol = true; } else if (text.Length == 0) { if (operation == Calculator.operations.Minus) { Plus(Calculator.Operation(operation)); operation_last_symbol = true; } } }
private CalculatorItem(CalculatorItem obj_1, CalculatorItem obj_2) { this.number = Merge(obj_1, obj_2); this.operation = obj_1.operation; }
public CalculatorItem(string number, char operation) { this.number = new FiveDigitInt(number); this.operation = Calculator.Operation(operation); }
public CalculatorItem(FiveDigitInt number, Calculator.operations operation) { this.number = number; this.operation = operation; }
public CalculatorItem() { this.number = new FiveDigitInt(); this.operation = Calculator.operations.Plus; }
private void BDivide_Click(object sender, RoutedEventArgs e) { temptotal = m_data.total; operation = operations.divide; newtotal = true; }
private void BMultiply_Click(object sender, RoutedEventArgs e) { temptotal = m_data.total; operation = operations.multiply; newtotal = true; }
private void BPlus_Click(object sender, RoutedEventArgs e) { temptotal = m_data.total; operation = operations.plus; newtotal = true; }
/// <summary> /// Calculates the result by solving the previousText and current text in the result /// box with the operand in currentOperation. /// </summary> private void calculateResult() { if (currentOperation == operations.NULL) { return; } double a = double.Parse(previousText); // first operand double b = double.Parse(resultBox.Text); // second operand double result; switch (currentOperation) { case operations.DIVISION: result = a / b; break; case operations.MULTIPLICATION: result = a * b; break; case operations.ADDITION: result = a + b; break; case operations.SUBTRACTION: result = a - b; break; case operations.POWER: result = Math.Pow(a, b); break; default: return; } if (errors.Contains(resultBox.Text)) { return; } operationCheck = false; previousText = null; string equation; // If a function button was not clicked during a mathematical operation then the equation box will have the text with the // format <operand a> <operation> <operand b as a number> else <operand a> <operation> <func>(<operand b>) if (!functionCheck) { equation = equationBox.Text + b.ToString(); } else { equation = equationBox.Text; functionCheck = false; } updateEquationBox(equation); showText(result.ToString()); currentOperation = operations.NULL; isResult = true; }
public void Operation(Calculator.operations operation) { input.Plus(operation); }