为什么我的服务费用不断说0而不是206?
我找不到为什么我的代码没有在油润滑油,冲洗和MISC复选框中添加到服务费用标签中。我在计算按钮中添加了它们,它们都被声明了,但我仍然以0的方式添加。最终以0?谢谢!
namespace Semester_Projectt
{
public partial class semesterProject : Form
{
double oilChange;
double lubeJob;
double radiatorFlush;
double transmissionFlush;
double inspection;
double muffler;
double tireRotation;
const double taxRate = 0.06;
public semesterProject()
{
InitializeComponent();
}
private double OilLubeCharges(double oilChange, double lubeJob)
{
return oilChange + lubeJob;
}
private double FlushCharges(double radiatorFlush, double transmissionFlush)
{
return radiatorFlush + transmissionFlush;
}
private double MiscCharges(double inspection, double muffler, double tireRotation)
{
return inspection + muffler + tireRotation;
}
private double OtherCharges(double parts, double labor)
{
return parts + labor;
}
private double TaxCharges(double parts)
{
if (parts != 0)
{
return (0.06 * parts);
}
else
return 0;
}
private double TotalCharges(double oilLube, double flush, double misc, double other, double tax)
{
return oilLube + flush + misc + other + tax;
}
private void clearButton_Click(object sender, EventArgs e)
{
ClearOilLube();
ClearFlushes();
ClearMisc();
ClearOther();
ClearFees();
}
private void ClearOilLube()
{
if(oilCheckBox.Checked == true)
{
oilCheckBox.Checked = false;
}
if(lubeCheckBox.Checked == true)
{
lubeCheckBox.Checked = false;
}
}
private void ClearFlushes()
{
if(radiatorCheckBox.Checked == true)
{
radiatorCheckBox.Checked = false;
}
if(transmissionCheckBox.Checked == true)
{
transmissionCheckBox.Checked = false;
}
}
private void ClearMisc()
{
if(inspectionCheckBox.Checked == true)
{
inspectionCheckBox.Checked = false;
}
if(mufflerCheckBox.Checked == true)
{
mufflerCheckBox.Checked = false;
}
if(tireCheckBox.Checked == true)
{
tireCheckBox.Checked = false;
}
}
private void ClearOther()
{
partsTextBox.Text = "";
laborTextBox.Text = "";
}
private void ClearFees()
{
serviceChargeLabel.Text = "";
additionalPartsLabel.Text = "";
additionalLaborLabel.Text = "";
taxLabel.Text = "";
totalFeesLabel.Text = "";
}
private void calculateButton_Click(object sender, EventArgs e)
{
double parts = double.Parse(partsTextBox.Text);
double labor = double.Parse(laborTextBox.Text);
double oilLube = OilLubeCharges(oilChange, lubeJob);
double flush = FlushCharges(radiatorFlush, transmissionFlush);
double misc = MiscCharges(inspection, muffler, tireRotation);
double other = OtherCharges(parts, labor);
double tax = TaxCharges(parts);
double total = TotalCharges(oilLube, flush, misc, other, tax);
double services = oilLube + flush + misc;
serviceChargeLabel.Text = services.ToString("c");
additionalPartsLabel.Text = parts.ToString("c");
additionalLaborLabel.Text = labor.ToString("c");
taxLabel.Text = tax.ToString("c");
totalFeesLabel.Text = total.ToString("c");
try
{
parts = double.Parse(partsTextBox.Text);
try
{
labor = double.Parse(laborTextBox.Text);
}
catch
{
MessageBox.Show("Entries must be numeric", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
partsTextBox.Focus();
partsTextBox.SelectAll();
}
}
catch
{
MessageBox.Show("Entries must be numeric", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
laborTextBox.Focus();
laborTextBox.SelectAll();
}
if (oilCheckBox.Checked == true)
{
oilChange = 26.00;
}
if (lubeCheckBox.Checked == true)
{
lubeJob = 18.00;
}
if (radiatorCheckBox.Checked == true)
{
radiatorFlush = 30.00;
}
if (transmissionCheckBox.Checked == true)
{
transmissionFlush = 80.00;
}
if (inspectionCheckBox.Checked == true)
{
inspection = 15.00;
}
if (mufflerCheckBox.Checked == true)
{
muffler = 100.00;
}
if (tireCheckBox.Checked == true)
{
tireRotation = 20.00;
}
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
I can't find out why my code is not adding in the oil lube, flush, and misc checkboxes towards the service charge label. I have them added in the calculate button and they are all declared but I still end up with 0. For example, if oil change, transmission flush, and muffler are checked i should end up with 206. Does anyone have an idea why i still end up with 0? Thanks!
namespace Semester_Projectt
{
public partial class semesterProject : Form
{
double oilChange;
double lubeJob;
double radiatorFlush;
double transmissionFlush;
double inspection;
double muffler;
double tireRotation;
const double taxRate = 0.06;
public semesterProject()
{
InitializeComponent();
}
private double OilLubeCharges(double oilChange, double lubeJob)
{
return oilChange + lubeJob;
}
private double FlushCharges(double radiatorFlush, double transmissionFlush)
{
return radiatorFlush + transmissionFlush;
}
private double MiscCharges(double inspection, double muffler, double tireRotation)
{
return inspection + muffler + tireRotation;
}
private double OtherCharges(double parts, double labor)
{
return parts + labor;
}
private double TaxCharges(double parts)
{
if (parts != 0)
{
return (0.06 * parts);
}
else
return 0;
}
private double TotalCharges(double oilLube, double flush, double misc, double other, double tax)
{
return oilLube + flush + misc + other + tax;
}
private void clearButton_Click(object sender, EventArgs e)
{
ClearOilLube();
ClearFlushes();
ClearMisc();
ClearOther();
ClearFees();
}
private void ClearOilLube()
{
if(oilCheckBox.Checked == true)
{
oilCheckBox.Checked = false;
}
if(lubeCheckBox.Checked == true)
{
lubeCheckBox.Checked = false;
}
}
private void ClearFlushes()
{
if(radiatorCheckBox.Checked == true)
{
radiatorCheckBox.Checked = false;
}
if(transmissionCheckBox.Checked == true)
{
transmissionCheckBox.Checked = false;
}
}
private void ClearMisc()
{
if(inspectionCheckBox.Checked == true)
{
inspectionCheckBox.Checked = false;
}
if(mufflerCheckBox.Checked == true)
{
mufflerCheckBox.Checked = false;
}
if(tireCheckBox.Checked == true)
{
tireCheckBox.Checked = false;
}
}
private void ClearOther()
{
partsTextBox.Text = "";
laborTextBox.Text = "";
}
private void ClearFees()
{
serviceChargeLabel.Text = "";
additionalPartsLabel.Text = "";
additionalLaborLabel.Text = "";
taxLabel.Text = "";
totalFeesLabel.Text = "";
}
private void calculateButton_Click(object sender, EventArgs e)
{
double parts = double.Parse(partsTextBox.Text);
double labor = double.Parse(laborTextBox.Text);
double oilLube = OilLubeCharges(oilChange, lubeJob);
double flush = FlushCharges(radiatorFlush, transmissionFlush);
double misc = MiscCharges(inspection, muffler, tireRotation);
double other = OtherCharges(parts, labor);
double tax = TaxCharges(parts);
double total = TotalCharges(oilLube, flush, misc, other, tax);
double services = oilLube + flush + misc;
serviceChargeLabel.Text = services.ToString("c");
additionalPartsLabel.Text = parts.ToString("c");
additionalLaborLabel.Text = labor.ToString("c");
taxLabel.Text = tax.ToString("c");
totalFeesLabel.Text = total.ToString("c");
try
{
parts = double.Parse(partsTextBox.Text);
try
{
labor = double.Parse(laborTextBox.Text);
}
catch
{
MessageBox.Show("Entries must be numeric", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
partsTextBox.Focus();
partsTextBox.SelectAll();
}
}
catch
{
MessageBox.Show("Entries must be numeric", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
laborTextBox.Focus();
laborTextBox.SelectAll();
}
if (oilCheckBox.Checked == true)
{
oilChange = 26.00;
}
if (lubeCheckBox.Checked == true)
{
lubeJob = 18.00;
}
if (radiatorCheckBox.Checked == true)
{
radiatorFlush = 30.00;
}
if (transmissionCheckBox.Checked == true)
{
transmissionFlush = 80.00;
}
if (inspectionCheckBox.Checked == true)
{
inspection = 15.00;
}
if (mufflerCheckBox.Checked == true)
{
muffler = 100.00;
}
if (tireCheckBox.Checked == true)
{
tireRotation = 20.00;
}
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用调试器逐步浏览您的代码,我想您会看到所有成本变量(即
oilchange
)是0时,将它们汇总在一起。显示消息框后,如果检查复选框,则有几个IF语句设置可变成本。看起来那是如果语句应移至过程的顶部。
Step through your code using the debugger and I think you'll see that all of your cost variables (i.e.
oilChange
) are 0 when you sum them together.After you show the MessageBoxes, you have several IF statements that set the variable costs if the checkboxes are checked. It looks like those IF statements should be moved to the top of the procedure.