public void undo() { if (OperationDisplay != "") { OperationDisplay = OperationDisplay.Remove(OperationDisplay.Length - 1); } int openingBrackets = 0; int closingBrackets = 0; for (int i = 0; i < OperationDisplay.Length; i++) { if (OperationDisplay[i] == '(') { openingBrackets++; } if (OperationDisplay[i] == ')') { closingBrackets++; } } if (openingBrackets > closingBrackets) { string x = OperationDisplay.Substring(OperationDisplay.LastIndexOf('(')); x = x.Trim('('); x = x.Trim('-'); OperationDisplay = OperationDisplay.Remove(OperationDisplay.LastIndexOf('(')); OperationDisplay += x; } }
public void signChange() { bool anyOperators = false; bool positiveSign = true; int index = 0; string x = ""; if (OperationDisplay.Length != 0 && !(OperationDisplay.LastIndexOfAny(operators.ToArray()) == OperationDisplay.Length - 1)) { for (int i = 0; i < 4; i++) { if (OperationDisplay.Contains(operators[i])) { anyOperators = true; } } if (anyOperators) { index = OperationDisplay.LastIndexOfAny(operators.ToArray()); } if (anyOperators && OperationDisplay.Substring(index - 1).Contains('(')) { positiveSign = false; } if (positiveSign) { if (index != 0) { x = OperationDisplay.Substring(index + 1); } else { x = OperationDisplay; } x = "(-" + x + ')'; if (index != 0) { OperationDisplay = OperationDisplay.Remove(index + 1); OperationDisplay += x; } else { OperationDisplay = x; } } else { x = OperationDisplay.Substring(index - 1); x = x.Trim('(', ')'); x = x.Trim('-'); OperationDisplay = OperationDisplay.Remove(index - 1); OperationDisplay += x; } } }