我的租车计划2 C#?

时间:2013-10-17 16:31:58

标签: c#

我的汽车计划需要帮助。我试图这样做,当你点击一个汽车单选按钮,让我说我想要一个布加迪,我会点击布加迪单选按钮,它将通过此​​代码计算最终成本:

bugattiDecimal = bugattiFinal * (Decimal)0.20 + rentedDecimal * 25;

该代码应该每英里计算0.20,每天租用25美元。

这是代码的其余部分:

//Step 3: Mathmatematical Calculations.
totalMilesDecimal = endingOdometerDecimal - beginningOdometerDecimal;
lamborghiniFinal = endingOdometerDecimal - beginningOdometerDecimal;
ferrariFinal = endingOdometerDecimal - beginningOdometerDecimal;
bugattiFinal = endingOdometerDecimal - beginningOdometerDecimal;
lamborghiniDecimal = lamborghiniFinal * (Decimal)0.12 + rentedDecimal * 15;
ferrariDecimal = ferrariFinal * (Decimal)0.15 + rentedDecimal * 20;
bugattiDecimal = bugattiFinal * (Decimal)0.20 + rentedDecimal * 25;

//This  shows the picture.
if (radLamborghini.Checked) {
   picLamborghini.Visible = true;
   picFerrari.Visible = false;
   picBugatti.Visible = false;
}

if (radLamborghini.Checked) {
   lblFinalCost.Text = lamborghiniDecimal.ToString();
}

private void radFerrari_CheckedChanged(object sender, EventArgs e)
{
   //This shows the picture.
   if (radFerrari.Checked) {
      picFerrari.Visible = true;
      picLamborghini.Visible = false;
      picBugatti.Visible = false;
   }

   if (radFerrari.Checked) {
      lblFinalCost.Text = ferrariDecimal.ToString();
   }
}

private void radBugatti_CheckedChanged(object sender, EventArgs e)
{
   //This shows the picture.
   if (radBugatti.Checked) {
      picBugatti.Visible = true;
      picLamborghini.Visible = false;
      picFerrari.Visible = false;
   }

   if (radBugatti.Checked) {
      lblFinalCost.Text = bugattiDecimal.ToString();
   }
}

我的代码是对的吗?当我点击其中一个单选按钮时,它们都会计算相同的费用。

1 个答案:

答案 0 :(得分:0)

看起来lamborghini位的代码不在事件处理程序中。这可能导致代码始终触发,如果您的其他单选按钮未连接到各自的事件,则lamborghini代码将始终运行,其他汽车的代码将不会运行。