Home > Net >  Why do my service charges keep saying 0 instead of 206?
Why do my service charges keep saying 0 instead of 206?

Time:04-28

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();
        }
    }
}

CodePudding user response:

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.

  • Related