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 { }
}
}
}
uj5u.com熱心網友回復:
a = new int[] {0,1500,4500,9000,35000,55000,80000};應納稅所得額是按升序排列的
計算時要逆序進行
uj5u.com熱心網友回復:
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陣列值錯了。
應是如上值。
uj5u.com熱心網友回復:
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了。
uj5u.com熱心網友回復:
計算時按逆序進行是什么意思。。。uj5u.com熱心網友回復:
8000055000
35000
9000
4500
1500
uj5u.com熱心網友回復:
還得把 if (income <= (theRecord.upperLimit + m_dThreshold))中的<=換成>=,并加上上面說的降序排列才能成功喲!uj5u.com熱心網友回復:
這個思路好,我也做過這個,就是用正序做的,還寫了一個很麻煩的演算法
用逆序做就很簡單了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/38110.html
標籤:C#
