Esempio n. 1
0
        public DateTime PerformOneDateCalculation()
        {
            userDate  = Prompts.UserInputDate("Please enter a date: mm/dd/yyyy");
            daysToAdd = Prompts.UserInput("Please enter the number of days to add:");

            dateCalculation = userDate.AddDays(daysToAdd);

            LogCalculations.Log($"Date {userDate}, days to add {daysToAdd}, answer {dateCalculation}");
            Console.WriteLine(dateCalculation.ToShortDateString());
            return(dateCalculation);
        }
        public int PerformOneCalculation()
        {
            Console.WriteLine("Enter an operator * - + /");
            myOperator = Console.ReadLine();

            numberOfnumbers = Prompts.UserInput(
                $"How many numbers do you want to {myOperator} ?");

            numbersArray = new int[numberOfnumbers];

            int count = 1;

            for (int i = 0; i < numbersArray.Length; i++)
            {
                myNumber        = Prompts.UserInput($"Please enter number {count}");
                count           = count + 1;
                numbersArray[i] = myNumber;
            }

            // calculator method to go through each number in array and apply operator to it
            answer = numbersArray[0];
            for (int i = 0; i < numbersArray.Length - 1; i++)
            {
                switch (myOperator)

                {
                case "*":
                    answer = answer * numbersArray[i + 1];
                    break;

                case "/":
                    answer = answer / numbersArray[i + 1];
                    break;

                case "+":
                    answer = answer + numbersArray[i + 1];
                    break;

                case "-":
                    answer = answer - numbersArray[i + 1];
                    break;
                }
            }

            LogCalculations.Log($"Operator {myOperator}, Numbers, {string.Join(", ", numbersArray)} answer {answer}");

            Console.WriteLine($"The answer is {answer}");
            return(answer);
        }
Esempio n. 3
0
        static int AskForCalculationMode()
        {
            var calculatorType = Prompts.UserInput("Which calculator do you want? \n 1) Numbers \n 2) Dates");

            return(calculatorType);
        }