我花了太多时间在理论上很简单。我的工资计算器仅在小时超过40小时时显示一个值。如果我输的少于40,那么输出是0.00英镑?一些指导意见将不胜感激:
hoursWorked = double.Parse(txtHoursWorked.Text); // change string to int
switch (rblJobRole.SelectedIndex)// set employees basic hourly rate
{
case 0: //engineer
basicHourRate = 10;
break;
case 1: //Senior Engineer
basicHourRate = 12;
break;
case 2: //Technical Engineer
basicHourRate = 25;
break;
case 3: //Supervisor
basicHourRate = 30;
break;
}
if (ckBEng.Checked) // if they have a certificate
{
certAmount = (basicHourRate * 10) / 100; // calculate 10% of hourly rate
basicHourRate = basicHourRate + certAmount; // add to hourly rate
basicWage = basicHourRate * hoursWorked; // basic wage set to include bonus.
}
if (hoursWorked > 40) // if employee worked more than 40hrs
{
overHrs = hoursWorked - regHrs; // calcualte over hours
basicWage = regHrs * basicHourRate; // calculate basic wage @ 40hrs only
overTimeRate = overHrs * (basicHourRate * 1.5); // calculate 50% bonus on 40+ hrs
basicWage = basicWage + overTimeRate; // calculate total wage
}
lblTotalWage.Text = basicWage.ToString("c"); // int to string to display Total Wage on a label
lblDescWage.Text = "You have earned: ";
答案 0 :(得分:3)
如果他们没有证书(ckBEng.Checked
是false
),并且他们不能使用&gt; 40小时(hoursWorked <= 40
),他们不拿钱: - )
if (ckBEng.Checked)
{
}
这里需要else
。
或者你搬家
basicWage = basicHourRate * hoursWorked;
在if