如何在计算中使用复选框
本文关键字:复选框 计算 | 更新日期: 2023-09-27 18:35:15
我正在尝试使用两个复选框执行以下操作。一个是医疗/牙科扣除,另一个是 401k 扣除。
如果您愿意,我可以为项目的其余部分提供我的代码。我正在尝试获得下面描述的所需输出。我收到此输出而不是所需的输出:
姓名:乔小时: 45评分: 10.00总工资: $400.00税: $112.50净薪: $337.50医疗/牙科扣除额: $400.00401k 扣除额: $20.00
· 处理两个可能的税前扣除(如果适用)(使用两个复选框):· 医疗/牙科扣除 - 如果选择
此选项,将从总工资中扣除 50.00 美元· 401k 扣除 – 如果选择此选项,将从总工资中扣除 5%· 税款在所有扣除后计算(适用扣除后金额的25%)· 在格式文本框中包含扣除金额,并正确标记每个金额
我还必须做一个测试用例,看看它是否有效:
· 输入:小时 = 45,费率 10.00,医疗/牙科和 401k 复选框均已选中· 产出:工资总额 = 475.00,医疗/牙科扣除额 50.00,401k 扣除额 = 23.75,税金 = 100.31,净工资 = 300.94
我试图开始这个,但不知道从哪里开始。我试了一下,这就是我所拥有的。它不在复选框方法中,而是在计算按钮方法中,其余计算是:
//Medical/Dental and 401k deductions...as well as tax collected.
if (MedicalDentalDeductions.Checked)
{
Gross_pay = Convert.ToInt32(HoursTextBox.Text) * decimal.Parse(RateTextBox.Text) - 50.00m;
}
if (FourOneKDeduction.Checked)
{
Gross_pay = Convert.ToInt32(HoursTextBox.Text) * decimal.Parse(RateTextBox.Text) - 0.05m * 100;
}
if ((MedicalDentalDeductions.Checked) && (FourOneKDeduction.Checked))
{ Taxes = TAX * Gross_pay; }
DisplayOutPut.Text= "Medical/Dental deduction:" + Taxes +"401k deduction:"+ Taxes;
}
我想你想要更多这样的东西:
//Medical/Dental and 401k deductions...as well as tax collected.
decimal Gross_pay= Convert.ToInt32(HoursTextBox.Text) * decimal.Parse(RateTextBox.Text);
decimal deductionMed = 0.00m;
decimal deduction401k = 0.00m
if (MedicalDentalDeductions.Checked)
{
deductionMed = - 50.00m;
}
if (FourOneKDeduction.Checked)
{
deduction401k = Gross_pay * 0.05m;
}
Taxes = TAX * (Gross_pay -(deductionMed + deduction401k));
DisplayOutPut.Text= "Medical/Dental deduction:" + deductionMed +" 401k deduction:"+ deduction401k + "Taxes:"+Taxes ;
}
尝试将其分解为逐步计算,就像在 excel 中或手动操作一样 -
int hours = 45;
double payRate = 10.00;
double taxRate = 0.25;
double gross = hours * payRate;
double medical = (MedicalDentalDeductions.Checked) ? 50 : 0;
double retirement = (ForOneKDeduction.Checked) ? gross * 0.05 : 0;
double pretax = gross - medical - retirement;
double tax = pretax * taxRate;
double net = gross - tax;