···
···
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();
}
}
}