为什么我的服务费用不断说0而不是206?

发布于 2025-01-23 22:00:12 字数 5721 浏览 0 评论 0原文

我找不到为什么我的代码没有在油润滑油,冲洗和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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟凡古楼 2025-01-30 22:00:12

使用调试器逐步浏览您的代码,我想您会看到所有成本变量(即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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文