示例#1
0
        /// <summary>
        /// Main application
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            while (true)
            {
                MathData mathData = ValueInterface.GetAllValuesFromCustomer();

                double finalResult = Calculations.GetResultValue(mathData);

                Console.WriteLine($"Wynik działania to: {finalResult}");
                Console.WriteLine("Kliknij przycisk Q, aby zakończyć...");
                string closingOperation = Console.ReadLine();
            }
        }
示例#2
0
        /// <summary>
        /// Data saving math method using custom dataMath object
        /// </summary>
        /// <param name="mathData"></param>
        /// <returns></returns>
        public static double GetResultValue(MathData mathData)
        {
            double result = 0;

            switch (mathData.Operation)
            {
            case "+":
                result = Add(mathData.FirstValue, mathData.SecondValue);
                break;

            case "-":
                result = Subtract(mathData.FirstValue, mathData.SecondValue);
                break;

            case "x":
            case "*":
                result = Multiply(mathData.FirstValue, mathData.SecondValue);
                break;

            case "/":
                if (mathData.SecondValue != 0)
                {
                    result = Divide(mathData.FirstValue, mathData.SecondValue);
                    break;
                }
                else
                {
                    Console.WriteLine("Nie dziel przez zero!");
                }
                break;

            default:
                Console.WriteLine("Podaj poprawny znak!");
                break;
            }

            return(result);
        }