Example #1
0
        // **********
        // Entrypoint
        // **********
        static void Main(string[] args)
        {
            // ***********************************************************************************
            // Fields :
            // calculator - RPNArithmetic handles math / management of the stored RPN expressions
            // previousCalculation - RPNToken storing previously the previously reduced expression
            // userInput - ConsoleKey storing current userInput
            // ***********************************************************************************
            RPNArithmetic calculator          = new RPNArithmetic();
            RPNToken      previousCalculation = new RPNToken("0");
            ConsoleKey    userInput;

            // **********************
            // Console User Interface
            // **********************
            do
            {
                DisplayMenu();
                userInput = Console.ReadKey().Key;
                switch (userInput)
                {
                case ConsoleKey.A:
                    Console.WriteLine();
                    GetRPNExpression(calculator);
                    break;

                case ConsoleKey.L:
                    Console.WriteLine(
                        "\n\nThe previous calculation was {0}.", previousCalculation);
                    break;

                case ConsoleKey.C:
                    CalculateAndDisplay(calculator, out previousCalculation);
                    break;

                case ConsoleKey.S:
                    calculator.Display();
                    break;

                case ConsoleKey.X:
                    calculator.Clear();
                    break;
                }
                Console.Write("\nPress any key to continue...  ");
                Console.ReadKey();
            }while (userInput != ConsoleKey.Q);
        }
Example #2
0
 private static void CalculateAndDisplay(RPNArithmetic calculator, out RPNToken previousCalculation)
 {
     previousCalculation = calculator.ReduceStack();
     Console.WriteLine("\n\nThe calculated value is {0}.", previousCalculation);
 }