用ASP.NET编写一个计算器(能实现加减乘除的)
2个回答
展开全部
贴个最简单的吧:
Operation类:
class Operation
{
public static double GetResult(double numberA, double numberB, string operate)
{
double result = 0d;
switch (operate)
{
case "+":
result = numberA + numberB;
break;
case "-":
result = numberA - numberB;
break;
case "*":
result = numberA * numberB;
break;
case "/":
result = numberA / numberB;
break;
}
return result;
}
}
Program.cs:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入数字A:");
string strNumberA = Console.ReadLine();
Console.WriteLine("请输入运算符号(+ - * /)");
string strOperate = Console.ReadLine();
Console.WriteLine("请输入数字B:");
string strNumberB = Console.ReadLine();
string strResult;
strResult = Convert.ToString(Operation.GetResult(Convert.ToDouble(strNumberA), Convert.ToDouble(strNumberB), strOperate));
Console.WriteLine("结果是:" + strResult);
Console.ReadLine();
}
}
Operation类:
class Operation
{
public static double GetResult(double numberA, double numberB, string operate)
{
double result = 0d;
switch (operate)
{
case "+":
result = numberA + numberB;
break;
case "-":
result = numberA - numberB;
break;
case "*":
result = numberA * numberB;
break;
case "/":
result = numberA / numberB;
break;
}
return result;
}
}
Program.cs:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入数字A:");
string strNumberA = Console.ReadLine();
Console.WriteLine("请输入运算符号(+ - * /)");
string strOperate = Console.ReadLine();
Console.WriteLine("请输入数字B:");
string strNumberB = Console.ReadLine();
string strResult;
strResult = Convert.ToString(Operation.GetResult(Convert.ToDouble(strNumberA), Convert.ToDouble(strNumberB), strOperate));
Console.WriteLine("结果是:" + strResult);
Console.ReadLine();
}
}
展开全部
贴个最简单的吧:
Operation类:
class
Operation
{
public
static
double
GetResult(double
numberA,
double
numberB,
string
operate)
{
double
result
=
0d;
switch
(operate)
{
case
"+":
result
=
numberA
+
numberB;
break;
case
"-":
result
=
numberA
-
numberB;
break;
case
"*":
result
=
numberA
*
numberB;
break;
case
"/":
result
=
numberA
/
numberB;
break;
}
return
result;
}
}
Program.cs:
class
Program
{
static
void
Main(string[]
args)
{
Console.WriteLine("请输入数字A:");
string
strNumberA
=
Console.ReadLine();
Console.WriteLine("请输入运算符号(+
-
*
/)");
string
strOperate
=
Console.ReadLine();
Console.WriteLine("请输入数字B:");
string
strNumberB
=
Console.ReadLine();
string
strResult;
strResult
=
Convert.ToString(Operation.GetResult(Convert.ToDouble(strNumberA),
Convert.ToDouble(strNumberB),
strOperate));
Console.WriteLine("结果是:"
+
strResult);
Console.ReadLine();
}
}
Operation类:
class
Operation
{
public
static
double
GetResult(double
numberA,
double
numberB,
string
operate)
{
double
result
=
0d;
switch
(operate)
{
case
"+":
result
=
numberA
+
numberB;
break;
case
"-":
result
=
numberA
-
numberB;
break;
case
"*":
result
=
numberA
*
numberB;
break;
case
"/":
result
=
numberA
/
numberB;
break;
}
return
result;
}
}
Program.cs:
class
Program
{
static
void
Main(string[]
args)
{
Console.WriteLine("请输入数字A:");
string
strNumberA
=
Console.ReadLine();
Console.WriteLine("请输入运算符号(+
-
*
/)");
string
strOperate
=
Console.ReadLine();
Console.WriteLine("请输入数字B:");
string
strNumberB
=
Console.ReadLine();
string
strResult;
strResult
=
Convert.ToString(Operation.GetResult(Convert.ToDouble(strNumberA),
Convert.ToDouble(strNumberB),
strOperate));
Console.WriteLine("结果是:"
+
strResult);
Console.ReadLine();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询