Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am making a simple program that is a class assignment. I cannot figure out how to wrap up the code.

What I have tried:

C#
public partial class frmPetClinic : Form
    {

 public frmPetClinic()
        {
            InitializeComponent();

            // Delcare varibles.

            Boolean bolFleaTreatment;
            Boolean bolHairTrim;
            Boolean bolNailTrim;
            Boolean bolDematting;
            Boolean bolHeartwormTreatmen;
            Boolean bolHepatitisVaccine;
            Boolean bolDistemperVaccine;
            Boolean bolRabiesVaccine;

            double dblCost;

            bolFleaTreatment = chkFleaTreatment.Checked;
            bolHairTrim = chkHairTrim.Checked;
            bolNailTrim = chkNailTrim.Checked;
            bolDematting = chkDematting.Checked;
            bolHeartwormTreatmen = chkHeartwormTreatment.Checked;
            bolHepatitisVaccine = chkHepatitisVaccine.Checked;
            bolDistemperVaccine = chkDistemperVaccine.Checked;
            bolRabiesVaccine = chkRabiesVaccine.Checked;

            dblCost = 0;

        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            //Exit the app.

            Application.Exit();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            //Clear selected checkboxes.
            //Clear running total.

            chkFleaTreatment.Checked = false;
            chkHairTrim.Checked = false;
            chkNailTrim.Checked = false;
            chkDematting.Checked = false;
            chkHeartwormTreatment.Checked = false;
            chkHepatitisVaccine.Checked = false;
            chkDistemperVaccine.Checked = false;
            chkRabiesVaccine.Checked = false;

            lblCost.Text = string.Empty;
        }

        private void chkFleaTreatment_CheckedChanged(object sender, EventArgs e)
        {

            // Decide which if any checkboxes are checked.
            // Add total costs and convert to currency

            // If box is unchecked, deduct price from cost
            if
                (true)

                
            else
                
        }
          

    }
        
}
Posted
Updated 12-Mar-17 16:05pm
v2

1 solution

based on the code you presented something like this should do the trick. Once you get everything working, then think of how to improve it, or make it shorter.

C#
public partial class frmPetClinic : Form
    {
double currentTotal = 0;
        double fleaTreatment = 112.5;
        double hairTrim = 88;
        System.Globalization.NumberStyles style =   System.Globalization.NumberStyles.Number | 
                                                    System.Globalization.NumberStyles.AllowCurrencySymbol;
        System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");

        private void chkFleaTreatment_CheckedChanged(object sender, EventArgs e)
        {
            
            double.TryParse(lblCost.Text, style, culture, out currentTotal);

            if (chkFleaTreatment.Checked)
            {
                lblCost.Text = Math.Round(currentTotal + fleaTreatment, 2).ToString("C2");
            }
            else
            {
                lblCost.Text = Math.Round(currentTotal - fleaTreatment, 2).ToString("C2");
            }
        }

        private void chkHairTrim_CheckedChanged(object sender, EventArgs e)
        {
            double.TryParse(lblCost.Text, style, culture, out currentTotal);

            if (chkHairTrim.Checked)
            {
                lblCost.Text = Math.Round(currentTotal + hairTrim, 2).ToString("C2");
            }
            else
            {
                lblCost.Text = Math.Round(currentTotal - hairTrim, 2).ToString("C2");
            }
        }

//private void chkNailTrim_CheckedChanged(object sender, EventArgs e)
//...

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900