今天考试又是写求个人所得税,开始学写程序的时候就写过,当前用很多IF来做(现在想起那种方法很笨).现在有了另一种算法(不知道再过一阵子,会不会觉得这个算法也很笨呢?所以SAVE一个),不知道还有没有更高级的算法.
static void Main(string[] args)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
Console.Write("请输入你本月的收入:");
float earning = float.Parse(Console.ReadLine());
float revenue = earning - 800;
float tax = 0;
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
float[] bourn =
{ 0, 500, 2000, 5000, 20000, 40000, 60000, 80000, 100000 };
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
float[] taxrate =
{ 5, 10, 15, 20, 25, 30, 35, 40, 45 };
![](/Images/OutliningIndicators/InBlock.gif)
for (int i = bourn.Length - 1; i >= 0; i--)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
float t = bourn[i];
if (revenue > t)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
float tmpTax = (revenue - t) * (taxrate[i] / 100);
tax += tmpTax;
![](/Images/OutliningIndicators/InBlock.gif)
revenue = t;
}
}
Console.WriteLine("你本月的收入为:{0},该月应缴所得税额为:{1},应缴纳的个人所得税额为:{2}", earning, earning - 800, tax);
Console.Read();
}