当两个复选框都被选中时,这是我想要的输入:
* *输入:小时 = 45,费率 10.00,医疗/牙科和 401k 复选框均已选中
这是我期望的输出:
· 输出:总工资 = 475.00,医疗/牙科扣除 = 50.00,401k 扣除 = 23.75,税收 = 100.31,净工资 = 300.94**
但是,当我在点击计算按钮并选中两个复选框(忽略名称)后运行我的项目时,我会收到此消息:
姓名:Joe 工作时间:45 费率:10.00 总收入:400.00 美元 税收:112.50 美元 净收入:337.50 美元 医疗/牙科扣除:400.00 美元 401k 扣除:20.00 美元
任何关于我做错了什么的帮助将不胜感激。我似乎无法弄清楚问题所在。
这是我在我的项目中拥有的:
这些变量在代码顶部声明:
private const decimal TAX = 0.25m;
private string name = "";
private decimal Gross_pay;
private decimal Taxes;
private decimal Net_Pay;
private decimal annual_salary;
private int NumberOfEmployees;
private decimal deductionMed;
private decimal deduction401k ;
这是计算发生的地方:
private void CalcButton_Click(object sender, EventArgs e)
{ // The “Calculate” button calculates gross pay, taxes, and net pay and then displays name, department, gross pay, taxes, and net pay using currency format for various amounts in the rich text box
// Gross pay= (hours * rate)
// Taxes= (25% of gross pay)
// Net pay (gross pay ?taxes)
//calculate
Gross_pay = Convert.ToInt32(HoursTextBox.Text) * decimal.Parse(RateTextBox.Text);
Taxes = TAX * Gross_pay;
Net_Pay = Gross_pay - Taxes;
annual_salary = Net_Pay;
Taxes = TAX * (Gross_pay - (deductionMed + deduction401k));
//overtime pay
if (Convert.ToInt32(HoursTextBox.Text) >= 41)
{
Gross_pay = Convert.ToInt32(HoursTextBox.Text) * decimal.Parse(RateTextBox.Text) * 1.5m;
DisplayOutPut.Text += "\nOvertime:" + Gross_pay.ToString("C") + "\n";
}
//Medical/Dental and 401k deductions...as well as tax collected.
if (MedicalDentalDeductions.Checked)
{
deductionMed = Gross_pay = Convert.ToInt32(HoursTextBox.Text) * decimal.Parse(RateTextBox.Text) - 50.00m;
}
if (FourOneKDeduction.Checked)
{
deduction401k = Gross_pay * 0.05m;
}
//display
DisplayOutPut.Text = "Name: "+ "";
DisplayOutPut.Text += NameTextBox.Text + "\n";
DisplayOutPut.Text += "Hours: " + HoursTextBox.Text + "\n";
DisplayOutPut.Text += "Rate: " + RateTextBox.Text + "\n";
DisplayOutPut.Text += "Gross Pay: " + Gross_pay.ToString("C") + "\n"; // Hours*Rate
DisplayOutPut.Text += "Taxes: " + Taxes.ToString("C") + "\n";
DisplayOutPut.Text += "Net Pay: " + Net_Pay.ToString("C");
DisplayOutPut.Text += "\nMedical/Dental deduction: " + deductionMed.ToString("C") + "\n401k deduction: " + deduction401k.ToString("C");
//handling the invalid inputs
if (NameTextBox.Text == "")
{ MessageBox.Show("Name is missing.", "Error"); }
if (Convert.ToInt32(HoursTextBox.Text) >= 70)
{ MessageBox.Show("Please Enter a Valid hour.", "Invalid data type."); }
if (RateTextBox.Text == "" && (RateTextBox.Text == ","))
{ MessageBox.Show("Please Enter a valid amount.", "Invalid data type ($)"); }
if (Convert.ToInt32(HoursTextBox.Text) >= 70)
{ MessageBox.Show("You have exceeded the maximum hours per week."); }
else if (Convert.ToInt32(HoursTextBox.Text) < 10)
{ MessageBox.Show("You cannot input less than 10 hours."); }
if (Convert.ToDecimal(RateTextBox.Text) < 9.75m)
{ MessageBox.Show("Please enter the minimum wage."); }
}
这些是复选框的方法:
private void MedicalDentalDeductions_CheckedChanged(object sender, EventArgs e)
{
}
private void FourOneKDeduction_CheckedChanged(object sender, EventArgs e)
{
}