vendredi 25 mars 2016

C# Having Multiple Check and Radio check boxes and doing calculations based on which are checked?

Alright so doing just a quick code to get the idea of using check and radio boxes in my code. Here is what I have got so far ( at the bottom ). So, I figured I can just set up a string of if statements and starting with seeing if all 3 are checked, if not it would go through and see if the first one is checked if not ect. Though, it does kind of work for only checking one check box, when I checked all three it displays the final calculation. So in my case if I have had 3 checked, it would only display the Volt + NonExploding calculation making it show $50,100 instead of $51,600 for if it added it all up. Can I get some quick help as to what to do so it notices that all three are checked instead of just going to the final checked calculation? Thanks for the help, very much appreciated.

        private void button_Calculate_Click(object sender, EventArgs e)
    {
        //Validating options 
        if (radioButton_ChevVolt.Checked || radioButton_FordPinto.Checked)
        {
            //no code needed
        }
        else
        {
            MessageBox.Show("Please Choose One of the Vehicles");
            return;
        }
        //Processing Input
        double SunRoof = 1000;
        double DVD = 500;
        double NonExploding = 100;
        double Volt = 50000;
        double Pinto = 1000;
        double TotalCost = 0;

        if (radioButton_ChevVolt.Checked)
                    {
                       TotalCost = Volt;
                       textBox_TotalCost.Text = TotalCost.ToString();
                    {
                    if (checkBox_SunRoof.Checked || checkBox_DVD.Checked || checkBox_NonExploding.Checked)
                    {
                       TotalCost = Volt + DVD + SunRoof + NonExploding;
                       textBox_TotalCost.Text = TotalCost.ToString();
                    }
                    if (checkBox_SunRoof.Checked)
                    {
                        TotalCost = Volt + SunRoof;
                        textBox_TotalCost.Text = TotalCost.ToString();
                    }
                    if (checkBox_DVD.Checked)
                    {
                        TotalCost = Volt + DVD;
                        textBox_TotalCost.Text = TotalCost.ToString();
                    }
                    if (checkBox_NonExploding.Checked)
                    {
                        TotalCost = Volt + NonExploding;
                        textBox_TotalCost.Text = TotalCost.ToString();
                    }


            }
        }



    }
}

}




Aucun commentaire:

Enregistrer un commentaire