美文网首页
2018-12-17

2018-12-17

作者: 一只皮皮橙 | 来源:发表于2018-12-17 12:30 被阅读0次

···

···

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApplication4

{

    class Program

    {

        static void Main(string[] args)

        {

            try

            {

                Console.Write("请选择运算:1加法 2减法 3乘法 4除法");

                int number = Convert.ToInt32(Console.ReadLine());

                if (number <= 4 && number > 0)

                {

                    Console.Write("请输入第1个数字:");

                    int x = Convert.ToInt32(Console.ReadLine());

                    Console.Write("请输入第2个数字:");

                    int y = Convert.ToInt32(Console.ReadLine());

                    switch (number)

                    {

                        case 1:

                            Console.WriteLine("******** 运算结果是:{0}", add(x, y));

                            break;

                        case 2:

                            Console.WriteLine("******** 运算结果是:{0}", jian(x, y));

                            break;

                        case 3:

                            Console.WriteLine("******** 运算结果是:{0}", cheng(x, y));

                            break;

                        case 4:

                            Console.WriteLine("******** 运算结果是:{0}", chu(x, y));

                            break;

                    }

                }

                else

                {

                    Console.WriteLine("请输入1~4,否则无效");

                }

            }

            catch

            {

                Console.WriteLine("您输入的程序错误");

            }

            Pause();

        }

        static int add(int x, int y)

        {

            return x += y;

        }

        static int jian(int x, int y)

        {

            return x -= y;

        }

        static int cheng(int x, int y)

        {

            return x *= y;

        }

        static int chu(int x, int y)

        {

            return x /= y;

        }

        static void Pause()

        {

            Console.ReadKey();

        }

    }

}

相关文章

网友评论

      本文标题:2018-12-17

      本文链接:https://www.haomeiwen.com/subject/ucvqkqtx.html