C# 基础语言 if..elsestring tax;decimal taxa;Console.WriteLine("Enter tax Y or N");Input = Console.ReadLine();tax = Convert.ToString(Input);if (tax == Y);{taxa=0.01;}else(tax == N);{taxa=0;}Console.WriteLine(taxa) 题要求输入Y 显示 10输入N

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/27 05:18:10
C#基础语言if..elsestringtax;decimaltaxa;Console.WriteLine("EntertaxYorN");Input=Console.ReadLine();tax=C

C# 基础语言 if..elsestring tax;decimal taxa;Console.WriteLine("Enter tax Y or N");Input = Console.ReadLine();tax = Convert.ToString(Input);if (tax == Y);{taxa=0.01;}else(tax == N);{taxa=0;}Console.WriteLine(taxa) 题要求输入Y 显示 10输入N
C# 基础语言 if..else
string tax;
decimal taxa;
Console.WriteLine("Enter tax Y or N");
Input = Console.ReadLine();
tax = Convert.ToString(Input);
if (tax == Y);
{
taxa=0.01;
}
else(tax == N);
{
taxa=0;
}
Console.WriteLine(taxa)
题要求
输入Y 显示 10
输入N 显示 0
我好像写的不对,应该如何改呢

C# 基础语言 if..elsestring tax;decimal taxa;Console.WriteLine("Enter tax Y or N");Input = Console.ReadLine();tax = Convert.ToString(Input);if (tax == Y);{taxa=0.01;}else(tax == N);{taxa=0;}Console.WriteLine(taxa) 题要求输入Y 显示 10输入N
static void Main(string[] args)
{
string tax;
decimal taxa;
Console.WriteLine("Enter tax Y or N");
tax = Console.ReadLine().ToString();
if (tax == "Y")
{
taxa = 10;
}
else if (tax == "N")
{
taxa = 0;
}
else
{
taxa = 100;
}
Console.WriteLine(taxa);
}
}
测试通过
因为你的taxa没有初始化,所以多了一个else判断,不然会报错,这儿如果觉得不行,可以初始化taxa给它一个值,取消掉多余的else判断