Beispiel #1
0
 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;
     }
 }
Beispiel #2
0
 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);
     }
 }
Beispiel #3
0
 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);
     }
 }
Beispiel #4
0
 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);
     }
 }
Beispiel #5
0
 static void Main(string[] args)
 {
     Calculator calc = new Calculator();
     InitCalculator(calc);
 }