コード例 #1
0
        static void Main(string[] args)
        {
            CalculatorRepository _calcRepo = new CalculatorRepository();
            decimal x = 0;
            decimal y = 0;
            decimal result;
            char    symbol;
            bool    isRunning = true;

            while (isRunning)
            {
                Console.WriteLine("Enter the number for your desired function: \n" +
                                  "\t1. Add two numbers\n" +
                                  "\t2. Subtract two numbers\n" +
                                  "\t3. Multiply two numbers\n" +
                                  "\t4. Divide two numbers\n" +
                                  "\t5. Get a remainder\n" +
                                  "\t6. Exit");
                var response = int.Parse(Console.ReadLine());
                switch (response)
                {
                case 1:
                    symbol    = '+';
                    x         = GetFirstValueForCalc();
                    y         = GetSecondValueForCalc();
                    result    = _calcRepo.AddTwoNumbers(x, y);
                    isRunning = PrintResults(x, y, result, symbol);
                    break;

                case 2:
                    symbol    = '-';
                    x         = GetFirstValueForCalc();
                    y         = GetSecondValueForCalc();
                    result    = _calcRepo.SubtractTwoNumbers(x, y);
                    isRunning = PrintResults(x, y, result, symbol);
                    break;

                case 3:
                    symbol    = '*';
                    x         = GetFirstValueForCalc();
                    y         = GetSecondValueForCalc();
                    result    = _calcRepo.MultiplyTwoNumbers(x, y);
                    isRunning = PrintResults(x, y, result, symbol);
                    break;

                case 4:
                    symbol    = '/';
                    x         = GetFirstValueForCalc();
                    y         = GetSecondValueForCalc();
                    result    = _calcRepo.DivideTwoNumbers(x, y);
                    isRunning = PrintResults(x, y, result, symbol);
                    break;

                case 5:
                    symbol    = '%';
                    x         = GetFirstValueForCalc();
                    y         = GetSecondValueForCalc();
                    result    = _calcRepo.GetRemainder(x, y);
                    isRunning = PrintResults(x, y, result, symbol);
                    break;

                case 6:
                    isRunning = false;
                    break;

                default:
                    symbol = '+';
                    decimal[] values = GetValues();
                    result    = _calcRepo.AddMultipleNumbers(values);
                    isRunning = PrintResults(result);
                    break;
                }
            }
        }