以下是代码实现
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("欢迎使用计算器,请输入两个操作数和运算符");
string input1 = Console.ReadLine();
int op1 = Convert.ToInt32(input1);
string input2 = (Console.ReadLine());
int op2= Convert.ToInt32(input2);
Console.WriteLine("请输入运算符:+,-,*,/");
string op = Console.ReadLine();
int result = 0;
if (op == "+")
{
result = op1 + op2;
}
else if (op == "-")
{
result= op1-op2;
}
else if (op == "*")
{
result = op1 * op2;
}
else if (op == "/")
{
if (op2 != 0)
{
result = op1 / op2;
}
else
{
Console.WriteLine("除数不能为0!");
}
}
else
{
Console.WriteLine("无效的运算符!");
}
Console.WriteLine("运算结果为:{0}",result);
}
}
}
下面是运行结果: