public virtual Calculator CalculateValues(Calculator calc, string mathOp) { if(mathOp == "+") { total = calc.x + calc.y; return calc; } else if(mathOp == "-") { total = calc.x - calc.y; return calc; } else if (mathOp == "*") { total = calc.x * calc.y; return calc; } else if (mathOp == "/") { total = calc.x / calc.y; return calc; } else { obj.LogCalculateError(x, y, mathOp); return calc; } }
private static void SecondVal(Calculator calc) { Console.Write("Enter another number: "); string s = Console.ReadLine(); if (calc.ParseInt(s)) { calc.y = Convert.ToInt32(s); Calculation(calc); } else // Go back 1 step { Console.WriteLine("Not a number."); SecondVal(calc); } }
private static void InitCalculator(Calculator calc) { Console.Write("Enter a number: "); string s = Console.ReadLine(); if (calc.ParseInt(s)) { calc.x = Convert.ToInt32(s); SecondVal(calc); } else // Go back 1 step { Console.WriteLine("Not a number."); string[] args = new string[0]; Main(args); } }
private static void Calculation(Calculator calc) { Console.Write("Enter an operator (+/-) "); string s = Console.ReadLine(); if (calc.parseMathOperator(s)) { calc.CalculateValues(calc, s); Console.WriteLine("Result: " + calc.total); SecondVal(calc); } else // Go back 1 step { Console.WriteLine("Not an operator."); Calculation(calc); } }
static void Main(string[] args) { Calculator calc = new Calculator(); InitCalculator(calc); }