Пример #1
0
 public static void Consider(Didgitals a)
 {
     if (a.typeFirstDidgit == typeof(int) & a.typeSecondDidgit == typeof(int))
     {
         Console.WriteLine("{0} + {1} = {2}", a.firstDidgit, a.secondDidgit, (int)Addition(a));
         Console.WriteLine("{0} - {1} = {2}", a.firstDidgit, a.secondDidgit, (int)Difference(a));
         Console.WriteLine("{0} * {1} = {2}", a.firstDidgit, a.secondDidgit, (int)Multiplication(a));
         Division(a, out string ex, out double rez);
         if (ex != "")
         {
             Console.WriteLine("{0} / {1} : {2}", a.firstDidgit, a.secondDidgit, ex);
         }
         else
         {
             Console.WriteLine(String.Format("{0} / {1} = {2:0.####}", a.firstDidgit, a.secondDidgit, (int)rez));
         }
     }
     if (a.typeFirstDidgit == typeof(double) | a.typeSecondDidgit == typeof(double))
     {
         Console.WriteLine(String.Format("{0} + {1} = {2:.####}", a.firstDidgit, a.secondDidgit, (double)Addition(a)));
         Console.WriteLine(String.Format("{0} - {1} = {2:0.####}", a.firstDidgit, a.secondDidgit, (double)Difference(a)));
         Console.WriteLine(String.Format("{0} * {1} = {2:.####}", a.firstDidgit, a.secondDidgit, (double)Multiplication(a)));
         Division(a, out string ex, out double rez);
         if (ex != "")
         {
             Console.WriteLine("{0} / {1} : {2}", a.firstDidgit, a.secondDidgit, ex);
         }
         else
         {
             Console.WriteLine(String.Format("{0} / {1} = {2:0.####}", a.firstDidgit, a.secondDidgit, (double)rez));
         }
     }
 }
Пример #2
0
 public static double Division(Didgitals a, out string ex, out double rez)
 {
     ex  = "";
     rez = 0;
     if (a.secondDidgit == 0)
     {
         ex  = "division by zero is forbidden!";
         rez = 0;
     }
     else
     {
         rez = a.firstDidgit / a.secondDidgit;
     }
     return(rez);
 }
Пример #3
0
        static void Main(string[] args)
        {
            while (true)
            {
                Didgitals      didgitals = new Didgitals();
                ConsoleKeyInfo keyInfo;
                while (true)
                {
                    Console.WriteLine("Enter fest didgital and press Enter: ");
                    string s = Console.ReadLine();
                    if (int.TryParse(s, out int nInt))
                    {
                        didgitals.typeFirstDidgit = nInt.GetType();
                        didgitals.firstDidgit     = (int)nInt;
                        break;
                    }
                    else if (double.TryParse(s, out double nDouble))
                    {
                        didgitals.typeFirstDidgit = nDouble.GetType();
                        didgitals.firstDidgit     = (double)nDouble;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Not a didgit!");
                    }
                }

                while (true)
                {
                    Console.WriteLine("Enter second didgital and press Enter: ");
                    string s = Console.ReadLine();
                    if (int.TryParse(s, out int nInt))
                    {
                        didgitals.typeSecondDidgit = nInt.GetType();
                        didgitals.secondDidgit     = (int)nInt;
                        break;
                    }
                    else if (double.TryParse(s, out double nDouble))
                    {
                        didgitals.typeSecondDidgit = nDouble.GetType();
                        didgitals.secondDidgit     = (double)nDouble;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Not a didgit!");
                    }
                }

                // реализация
                Consider(didgitals);

                Console.WriteLine("for exit press Escape / for continue press any button: ");

                keyInfo = Console.ReadKey(true);
                if (keyInfo.Key == ConsoleKey.Spacebar)
                {
                    break;
                }
            }
        }
Пример #4
0
 public static double Multiplication(Didgitals a)
 {
     return(a.firstDidgit * a.secondDidgit);
 }
Пример #5
0
 public static double Difference(Didgitals a)
 {
     return(a.firstDidgit - a.secondDidgit);
 }
Пример #6
0
 public static double Addition(Didgitals a)
 {
     return(a.firstDidgit + a.secondDidgit);
 }