コード例 #1
0
        public static void Main(String[] args)
        {
            Calculator c = new Calculator();
            char       a;
            String     val;
            int        n1, n2, ans;

            Console.Write("Enter integer: ");
            val = Console.ReadLine();
            n1  = Convert.ToInt32(val);
            Console.Write("Enter integer: ");
            val = Console.ReadLine();
            n2  = Convert.ToInt32(val);
            Console.Write("Enter operation: ");
            val = Console.ReadLine();
            a   = Convert.ToChar(val);
            switch (a)
            {
            case '+':
                ans = c.Add(n1, n2);
                Console.WriteLine("result: ");
                Console.WriteLine(ans);
                break;

            case '-':
                ans = c.Sub(n1, n2);
                Console.WriteLine("result: ");
                Console.WriteLine(ans);
                break;

            case '*':
                ans = c.Mul(n1, n2);
                Console.WriteLine("result: ");
                Console.WriteLine(ans);
                break;

            case '/':
                ans = c.Div(n1, n2);
                Console.WriteLine("result: ");
                Console.WriteLine(ans);
                break;
            }
            Console.ReadKey();
        }