这次要 首先判定输出是不是数字,然后可以 加, 减, 乘, 除计算
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
//判定输入是不是数字
//可以做4种计算
//打印出结果
class Program
{
static void Main(string[] args)
{
int a = 0;
string inputString ="";
bool isNumber = false;
Console.WriteLine("请输入数字");
do
{
inputString = Console.ReadLine();
if (!int.TryParse(inputString,out a))
Console.WriteLine("请输入第一个数字");
else
isNumber =true;
{
}
} while (!isNumber);
int b;
string n;
Console.WriteLine("请输入第二个数字");
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入\"+\",\"-\",\"*\",\"/\"任意1种运算符");
n = Console.ReadLine();
if (n == "+")
{
Console.WriteLine("{0} + {1} = {2}", a, b, a + b);
}
if (n == "-")
{
Console.WriteLine("{0} - {1} = {2}", a, b, a - b);
}
if (n == "*")
{
Console.WriteLine("{0} * {1} = {2}", a, b, a * b);
}
if (n == "/")
{
Console.WriteLine("{0} / {1} = {2}", a, b, a / b);
}
Console.ReadKey();
}
}
}