您好!这段代码我也刚写完,看看对您是否有帮助
这个四则运算程序是循环的,并且运算符输错会提示重新输入
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 计算器
{
class Program
{
static void Main(string[] args)
{
int x = 1;
do
{
Console.Write("请输入第一个数字:");
double a = Convert.ToDouble(Console.ReadLine());
Console.Write("请输入第二个数字:");
double b = Convert.ToDouble(Console.ReadLine());
Console.Write("请输入运算符:");
string c = Console.ReadLine();
if (c == "+" || c == "-" || c == "*" || c == "/")
{
switch (c)
{
case "+":
Console.WriteLine("" + a + "" + c + "" + b + "=" + (a + b));
break;
case "-":
Console.WriteLine("" + a + "" + c + "" + b + "=" + (a - b));
break;
case "*":
Console.WriteLine("{0}{1}{2}={3}", a, c, b, (a * b));
break;
case "/":
Console.WriteLine("{0}{1}{2}={3}", a, c, b, (a / b));
break;
}
}
/*else if (!IsNum(a))
{
Console.WriteLine("您的输入有错!请重新输入(*^__^*) 嘻嘻……");
x = 1;
* }*/
else
{
Console.WriteLine("您的输入有错!请重新输入(*^__^*) 嘻嘻……");
x = 1;
}
} while (x ==1);
}
}