private static CalculatorType AskForCalculationMode() { Console.WriteLine("Which calculator mode do you want?"); Console.WriteLine(" {0}) Numbers", (int)CalculatorType.Number); Console.WriteLine(" {0}) Dates", (int)CalculatorType.Date); return((CalculatorType)Prompts.AskForNumber("> ")); }
public void PerformOneCalculation() { var date = Prompts.AskForDate("Please enter a date: "); var number = Prompts.AskForNumber("Please enter the number of days to add: "); var answer = date.AddDays(number); logger.LogCalculation($"{date:dd/MM/yyyy} + {number}", answer.ToString("dd/MM/yyyy")); Console.WriteLine("The answer is: {0:dd/MM/yyyy}", answer); Console.WriteLine(); }
public void PerformOneCalculation() { var op = Prompts.AskForString("Please enter the operator: "); var numbers = Prompts.AskForNumberArray($"Please enter the numbers to {op}. "); var answer = CalculateAnswer(op, numbers); logger.LogCalculation(string.Join(op, numbers), answer.ToString()); Console.WriteLine("The answer is: {0}", answer); Console.WriteLine(); }
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); }
static int AskForCalculationMode() { var calculatorType = Prompts.UserInput("Which calculator do you want? \n 1) Numbers \n 2) Dates"); return(calculatorType); }