我说这个C#代码有错误"错误1无法隐式转换类型' double' to' int'。存在显式转换(您是否错过了演员?)" 错误在哪里?
Console.Write("Input money : ");
float money;
int tax;
if (money < 10000)
{
tax = .05 * money;
}
else if (money <= 100000)
{
tax = .08 * money;
}
else
{
tax = .085 * money;
}
Console.WriteLine("Tax is {0}", tax);
Console.ReadLine();
}
}
答案 0 :(得分:1)
将您的可变税改为双倍
double tax = 0;
工作守则,
Console.Write("Input money : ");
float money = Console.Read();
double tax = 0;
if (money < 10000)
{
tax = .05 * money;
}
else if (money <= 100000)
{
tax = .08 * money;
}
else
{
tax = .085 * money;
}
Console.WriteLine("Tax is {0}", tax);
Console.ReadLine();
答案 1 :(得分:1)
tax
是int
,您尝试为其分配float
值。
您必须将tax
/ float
/ double
声明为decimal
或以某种方式对其值进行四舍五入。
编辑:如果你不初始化money
的值,使用Console.ReadLine()
并解析其返回值