个人税率计算器。C#编程,得不到想要的答案,求助啊......

AllenYAL 2018-04-21 01:35:54
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 税率计算器Yal
{
public partial class Form1 : Form
{
struct TaxRecord
{
public double upperLimit;
public double TaxRate;
public double deduction;
}
private TaxRecord[] m_taxTable = new TaxRecord[7];
private const double m_dThreshold = 3500;
public Form1()
{
InitializeComponent();
}

private void btnQuit_Click(object sender, EventArgs e)
{
this.Close();
}

private void btnOk_Click(object sender, EventArgs e)
{
try
{
int[] a; double[] b; int[] c;
a = new int[] {0,1500,4500,9000,35000,55000,80000};
b = new double[] {0.3,0.10,0.20,0.25,0.30,0.35,0.45};
c = new int[] {0,105,555,1005,2755,5505,13505};
int Q = 0;
for (int i = 0; i < 7; i++)
{
m_taxTable[Q].upperLimit = a[i];
m_taxTable[Q].TaxRate = b[i];
m_taxTable[Q].deduction = c[i];
Q++;
}
double income = Convert.ToDouble(txtIncome.Text);
double taxes = 0;
if (income - m_dThreshold > 0)
{
foreach (TaxRecord theRecord in this.m_taxTable)
{
if (income <= (theRecord.upperLimit + m_dThreshold))
{
taxes = (income - m_dThreshold) * theRecord.TaxRate - theRecord.deduction;
break;
}
}
}
double incomeAfterTaxes = income - taxes;
this.txtIncomeAfterTaxes.Text = incomeAfterTaxes.ToString("0.00");
this.txtTaxes.Text = taxes.ToString("0.00");
}
catch { }
}

}
}
...全文
1066 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
还得把 if (income <= (theRecord.upperLimit + m_dThreshold))中的<=换成>=,并加上上面说的降序排列才能成功哟!
aquayhy 2020-05-21
  • 打赏
  • 举报
回复
引用 2 楼 xuzuning 的回复:
a = new int[] {0,1500,4500,9000,35000,55000,80000}; 应纳税所得额是按升序排列的 计算时要逆序进行
这个思路好,我也做过这个,就是用正序做的,还写了一个很麻烦的算法 用逆序做就很简单了。
xuzuning 2018-04-26
  • 打赏
  • 举报
回复
80000 55000 35000 9000 4500 1500
AllenYAL 2018-04-26
  • 打赏
  • 举报
回复
计算时按逆序进行是什么意思。。。
sunylf 2018-04-23
  • 打赏
  • 举报
回复
a = new int[] {0,1500,4500,9000,35000,55000,80000}; b = new double[] {0.03,0.10,0.20,0.25,0.30,0.35,0.45}; c = new int[] {0,105,555,1005,2755,5505,13505}; 你的B数组值错了。 应是如上值。 0.03,你搞成0.3了。
sunylf 2018-04-23
  • 打赏
  • 举报
回复
a = new int[] {0,1500,4500,9000,35000,55000,80000}; b = new double[] {0,0.10,0.20,0.25,0.30,0.35,0.45}; c = new int[] {0,105,555,1005,2755,5505,13505}; 你的B数组值错了。 应是如上值。
xuzuning 2018-04-23
  • 打赏
  • 举报
回复
a = new int[] {0,1500,4500,9000,35000,55000,80000}; 应纳税所得额是按升序排列的 计算时要逆序进行

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧