我不知道為什么我的代碼沒有在服務費標簽上添加潤滑油、沖洗和雜項復選框。我在計算按鈕中添加了它們,它們都被宣告了,但我仍然以 0 結束。例如,如果檢查換油、變速箱沖洗和消音器,我應該以 206 結束。有誰知道為什么我仍然以 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();
}
}
}
uj5u.com熱心網友回復:
oilChange使用除錯器單步執行您的代碼,我認為當您將它們加在一起時,您會看到所有成本變數(即)都是 0。
顯示 MessageBox 后,如果選中復選框,您將有幾個設定可變成本的 IF 陳述句。看起來那些 IF 陳述句應該移到程序的頂部。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/466306.html
