Hi
I think your application has some problems:
The first one, you must read price from a table. because price will be change as soon as therefore you must design a form for change that and save that in a table or Xml data file.
The second one, you must implement a way for calculate total price. for this section I have two suggestion:
1- You can use from a Property as TotalPrice and store and read value.
private double DessertPrice { get; set; }
private double EntreePrice { get; set; }
private double AppetizerPrice { get; set; }
private double TotalPrice { get; set; }
private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
{
if (comboBox3.SelectedIndex == 0)
DessertPrice = 3.00;
else if (comboBox3.SelectedIndex == 1)
DessertPrice = 2.00;
else if (comboBox3.SelectedIndex == 2)
DessertPrice = 2.50;
else
DessertPrice = 2.00;
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.SelectedIndex == 0)
EntreePrice = 25.00;
else if (comboBox2.SelectedIndex == 1)
EntreePrice = 15.00;
else if (comboBox2.SelectedIndex == 2)
EntreePrice = 12.00;
else
EntreePrice = 20.00;
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == 0)
AppetizerPrice = 3.00;
else if (comboBox1.SelectedIndex == 1)
AppetizerPrice = 5.00;
else if (comboBox1.SelectedIndex == 2)
AppetizerPrice = 3.00;
else
AppetizerPrice = 3.00;
}
private void button1_Click_1(object sender, EventArgs e)
{
TotalPrice = DessertPrice + EntreePrice + AppetizerPrice;
MessageBox.Show(string.Format("Your total is {0}.", TotalPrice));
DessertPrice = 0;
EntreePrice = 0;
AppetizerPrice = 0;
TotalPrice = 0;
}
2- You can use from a class for this problem. (I think it is best way)
public class Price
{
internal double DessertPrice { get; set; }
internal double EntreePrice { get; set; }
internal double AppetizerPrice { get; set; }
internal double TotalPrice { get; set; }
public Price()
{
DessertPrice = 0;
EntreePrice = 0;
AppetizerPrice = 0;
TotalPrice = 0;
}
public double CalculateTotalPrice()
{
TotalPrice = DessertPrice + EntreePrice + AppetizerPrice;
}
}
Price price = new Price();
private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
{
if (comboBox3.SelectedIndex == 0)
price.DessertPrice = 3.00;
else if (comboBox3.SelectedIndex == 1)
price.DessertPrice = 2.00;
else if (comboBox3.SelectedIndex == 2)
price.DessertPrice = 2.50;
else
price.DessertPrice = 2.00;
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.SelectedIndex == 0)
price.EntreePrice = 25.00;
else if (comboBox2.SelectedIndex == 1)
price.EntreePrice = 15.00;
else if (comboBox2.SelectedIndex == 2)
price.EntreePrice = 12.00;
else
price.EntreePrice = 20.00;
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == 0)
price.AppetizerPrice = 3.00;
else if (comboBox1.SelectedIndex == 1)
price.AppetizerPrice = 5.00;
else if (comboBox1.SelectedIndex == 2)
price.AppetizerPrice = 3.00;
else
price.AppetizerPrice = 3.00;
}
private void button1_Click_1(object sender, EventArgs e)
{
MessageBox.Show(string.Format("Your total is {0}.", price.CalculateTotalPrice()));
}
I hope it's helpful for you.