C#简易运算器程序问题
各位同学,最近我在用C#做计算器过程中发现一个问题。以下是我问题的简单代码和截图:8.6-8.3=0.29999999999? 5.3-5.2=0.0999999999999996?????using System;
public class Compute
{
static void Main()
{
double num1=0;
double num2=0;
double result;
string oper;
string flag="Y",num1Str,num2Str;
while(flag=="Y"||flag=="y")
{
Console.WriteLine("*****************简易运算程序****************");
Console.WriteLine("请输入第一个操作数num1:");
num1Str=Console.ReadLine();
num1=Double.Parse(num1Str);
Console.WriteLine("请输入第二个操作数num2:");
num2Str=Console.ReadLine();
num2=Double.Parse(num2Str);
Console.WriteLine("请输入运算符oper:");
oper=Console.ReadLine();
switch(oper)
{
case"+":
Console.WriteLine("加法运算结果:");
result=num1+num2;
Console.WriteLine(Convert.ToString(result));
break;
case"-":
Console.WriteLine("减法运算结果:");
result=num1-num2;
Console.WriteLine(Convert.ToString(result));
break;
case"*":
Console.WriteLine("乘法运算结果:");
result=num1*num2;
Console.WriteLine(Convert.ToString(result));
break;
case"/":
if (num2==0)
Console.WriteLine("除数不能为0");
else
{
Console.WriteLine("除法运算结果:");
result=num1/num2;
Console.WriteLine(Convert.ToString(result));
}
break;
default:
Console.WriteLine("无法识别运算表达式!");
break;
}
Console.WriteLine("************************************");
Console.WriteLine("是否继续:'Y/y' OR 'N/n':");
flag=Console.ReadLine();
}
}
}