用C#做一个小学算术题软件该怎么做?
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/28 02:27:55
![用C#做一个小学算术题软件该怎么做?](/uploads/image/z/6901723-19-3.jpg?t=%E7%94%A8C%23%E5%81%9A%E4%B8%80%E4%B8%AA%E5%B0%8F%E5%AD%A6%E7%AE%97%E6%9C%AF%E9%A2%98%E8%BD%AF%E4%BB%B6%E8%AF%A5%E6%80%8E%E4%B9%88%E5%81%9A%3F)
用C#做一个小学算术题软件该怎么做?
用C#做一个小学算术题软件该怎么做?
用C#做一个小学算术题软件该怎么做?
namespace 计算器控制台
{
class Program
{
static void Main(string[] args)
{
try
{
Console.Write("请输入数字A:");
string strNumberA = Console.ReadLine();
Console.Write("请选择运算符号(+、-、*、/):");
string strOperate = Console.ReadLine();
Console.Write("请输入数字B:");
string strNumberB = Console.ReadLine();
string strResult = "";
Operation oper;
oper = OperationFactory.createOperate(strOperate);
oper.NumberA = Convert.ToDouble(strNumberA);
oper.NumberB = Convert.ToDouble(strNumberB);
strResult = oper.GetResult().ToString();
Console.WriteLine("结果是:" + strResult);
Console.ReadLine();
}
catch (Exception ex) //当输入错误时,显示错误信息
{
Console.WriteLine("您的输入有错:" + ex.Message);
Console.ReadLine(); //自己加的
}
}
}
}