public void Calculate(InputData inputData) { if (inputData.CorrectInput) switch (inputData.OperatorType) { case '+': { Console.WriteLine("\nResult: " + (inputData.FirstOperand + inputData.SecondOperand)); break; } case '-': { Console.WriteLine("\nResult: " + (inputData.FirstOperand - inputData.SecondOperand)); break; } case '*': { Console.WriteLine("\nResult: " + (inputData.FirstOperand * inputData.SecondOperand)); break; } case '/': { Console.WriteLine("\nResult: " + (inputData.FirstOperand / inputData.SecondOperand)); break; } default: { Console.WriteLine("\nOperation is not supported."); break; } } else Console.WriteLine("\nIncorrect input!"); }
public InputData ReadInputData() { InputData inputData = new InputData(); try { Console.Write("Input first operand: "); inputData.FirstOperand = Convert.ToDouble(Console.ReadLine()); Console.Write("Input operator: "); inputData.OperatorType = Convert.ToChar(Console.ReadLine()); Console.Write("Input second operand: "); inputData.SecondOperand = Convert.ToDouble(Console.ReadLine()); inputData.CorrectInput = true; } catch { inputData.CorrectInput = false; } return inputData; }