using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
//死循环无限计算
for ( ; ; )
{
//控制台获取计算
Console.WriteLine("输入第一个数");
int a = int.Parse(Console.ReadLine());
Console.WriteLine("输入计算方式 (+ - * / %)");
string b = Console.ReadLine();
Console.WriteLine("输入第二个数");
int c = int.Parse(Console.ReadLine());
int d;
//if判断计算方式
if (b == "+")
{
d = a + c;
Console.WriteLine("计算结果为" + d);
}
else if (b == "-")
{
d = a - c;
Console.WriteLine("计算结果为" + d);
}
else if (b == "*")
{
d = a * c;
Console.WriteLine("计算结果为" + d);
}
else if (b == "/")
{
if (a == 0)
{
Console.WriteLine("零做除数没有意义");
}
else
{
d = a / c;
Console.WriteLine("计算结果为" + d);
}
}
else if (b == "%")
{
d = a % c;
Console.WriteLine("计算结果为" + d);
}
else
{
Console.WriteLine("请输入正确的运算符" );
}
}
}
}
}
C#简单的计算器功能
猜你喜欢
转载自blog.csdn.net/qq_28058231/article/details/108660418
今日推荐
周排行