static void Main(string[] args) { double a = EnterNumber1(); char operation = EnterOperator(); double b = EnterNumber2(); Calculation c = new Calculation(); switch (operation) { case '+': PrintResult(c.Sum(a, b).ToString()); break; case '-': PrintResult(c.Diff(a, b).ToString()); break; case '*': PrintResult(c.Multiply(a, b).ToString()); break; case '/': PrintResult(c.Division(a, b).ToString()); break; case '%': PrintResult(c.RemainderOfDivision(a, b).ToString()); break; } Console.ReadLine(); }
private void ExecuteOperation() { switch (Operation) { case "+": LabelResult.Text = Calculation.Summin(FirstNum, SecondNum).ToString(); break; case "-": LabelResult.Text = Calculation.Subtraction(FirstNum, SecondNum).ToString(); break; case "*": LabelResult.Text = Calculation.Multiplication(FirstNum, SecondNum).ToString(); break; case "/": LabelResult.Text = Calculation.Division(FirstNum, SecondNum); break; case "^": LabelResult.Text = Calculation.Exponentiation(FirstNum, SecondNum).ToString(); break; case "root": LabelResult.Text = Calculation.RootExtraction(FirstNum, SecondNum); break; default: break; } }
static void Main(string[] args) { int a = EnterNumber1(); char operation = EnterOperator(); int b = EnterNumber2(); Calculation calc = new Calculation(); switch (operation) { case '+': PrintResult(calc.Sum(a, b).ToString()); break; case '-': PrintResult(calc.Diff(a, b).ToString()); break; case '*': PrintResult(calc.Multiply(a, b).ToString()); break; case '/': try { PrintResult(calc.Division(a, b).ToString()); } catch (DivideByZeroException) { Console.WriteLine("Divide by zero"); } break; } Console.ReadKey(); }