Beispiel #1
0
 public static void MyCalculator()
 {
     PrintWelcomeMessage();
     while (true)
     {
         int calculationMode = AskForCalculationMode();
         if (calculationMode == NumberCalculator)
         {
             NumberCalculatorClass.PerformOneNumberCalculation();
         }
         else if (calculationMode == DateCalculator)
         {
             DateCalculatorClass.PerformOneDateCalculation();
         }
     }
 }
        private static DateTime CalcDateDays()
        {
            Console.WriteLine(@"Please enter the number of days.
To subtract, just enter a negative number e.g. -10");
            int      daysX    = NumberCalculatorClass.ConvertNum();
            DateTime daysCalc = DateTime.Now.AddDays(daysX);
            string   daysDate = daysCalc.ToShortDateString();
            int      daysY    = daysX * -1;

            if (daysX >= 0)
            {
                Console.Write($@"The date {daysX} days from now will be {daysDate}
");
            }
            else
            {
                Console.WriteLine($@"The date {daysY} days ago was {daysDate}
");
            }
            return(daysCalc);
        }
        private static DateTime CalcTwoDateDays()
        {
            DateTime dateY = ConvertDate();

            Console.WriteLine("Please enter the number of days: (To subtract, just enter a negative number e.g. -10)");
            int      daysX    = NumberCalculatorClass.ConvertNum();
            string   dateYStr = dateY.ToShortDateString();
            DateTime daysCalc = dateY.AddDays(daysX);
            string   daysDate = daysCalc.ToShortDateString();

            if (daysX >= 0)
            {
                Console.Write($@"{daysX} days after {dateYStr} is {daysDate}
");
            }
            else
            {
                Console.WriteLine($@"{daysX} days before {dateYStr} is {daysDate}
");
            }

            return(daysCalc);
        }