超简单的计算器。 不准笑哈
using System;class jsq
{
public double jiafa(double a, double b)
{
double reasult;
reasult = a + b;
return reasult;
}
public double jianfa(double a, double b)
{
double reasult;
reasult = a - b;
return reasult;
}
public double chengfa(double a, double b)
{
double reasult;
reasult = a * b;
return reasult;
}
public double chufa(double a, double b)
{
double reasult;
reasult = a / b;
return reasult;
}
static void Main(string[] args)
{
double a;
double b;
double c;
string d;
Console.WriteLine("请输入第一个数字");
a = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("请输入第二个数字");
b = Convert.ToDouble(Console.ReadLine());
jsq js = new jsq();
Console.WriteLine("请输入你要进行的计算方式:");
Console.Write("+\t-\t*\t/");
Console.WriteLine();
d = Console.ReadLine();
switch (d)
{
case "+":
{
c = js.jiafa(a, b);
Console.WriteLine("加法结果为:{0}", c);
}
break;
case "-":
{
c = js.jianfa(a, b);
Console.WriteLine("减法结果为:{0}", c);
}
break;
case "*":
{
c = js.chengfa(a, b);
Console.WriteLine("乘法结果为:{0}", c);
}
break;
case "/":
{
if (b != 0)
{
c = js.chufa(a, b);
Console.WriteLine("加法结果为:{0}", c);
}
else
{
Console.WriteLine("除法结果为:Error ! 除数不能为0");
}
}
break;
default :
Console.WriteLine("本计算器目前只支持'+','-','*','/'");
break;
}
Console.ReadLine();
}
}