private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (smallPizza.Checked)
{
int smallPizzaPrice = 9;
pizzaTotal += smallPizzaPrice;
}
}
when I send the value of this to a text box it gives the correct value '9'
private void mediumPizza_CheckedChanged_1(object sender, EventArgs e)
{
if (mediumPizza.Checked)
{
int mediumPizzaPrice = 12;
pizzaTotal += mediumPizzaPrice;
}
}
when I send this value to the same text box I get '21'
I have code for a large pizza in which I initialise the price at 14 but the value 23 is sent to the textbox.
The rest of the code:
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double pizzaTotal = 0;
double finalPizzaTotal = 0;
double finalPrice =0;
string totalPrice = "";
private void button3_Click(object sender, EventArgs e)
{
orderTotal.Text += finalPrice;
double totalVat = finalPrice * .21;
totalAfterVat.Text += finalPrice + totalVat;
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (smallPizza.Checked)
{
int smallPizzaPrice = 9;
pizzaTotal += smallPizzaPrice;
}
}
private void mediumPizza_CheckedChanged_1(object sender, EventArgs e)
{
if (mediumPizza.Checked)
{
int mediumPizzaPrice = 12;
pizzaTotal += mediumPizzaPrice;
}
}
private void largePizza_CheckedChanged(object sender, EventArgs e)
{
if (largePizza.Checked)
{
pizzaTotal += 14;
}
}
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
if (pineappple.Checked) {
pizzaTotal += 0.5;
}
}
private void calculateTotal_Click(object sender, EventArgs e)
{
costOfPizza.Text = String.Empty;
finalPizzaTotal += pizzaTotal;
pizzaTotal = 0;
finalPrice += finalPizzaTotal;
costOfPizza.Text = costOfPizza.Text + finalPizzaTotal;
}
private void margeritta_CheckedChanged(object sender, EventArgs e)
{
if (margeritta.Checked)
{
pizzaTotal += 1;
}
}
private void Pepperoni_CheckedChanged(object sender, EventArgs e)
{
if (pepperoni.Checked) {
pizzaTotal += 2;
}
}
private void hawaiian_CheckedChanged(object sender, EventArgs e)
{
if (hawaiian.Checked)
{
pizzaTotal += 3;
}
}
private void salami_CheckedChanged(object sender, EventArgs e)
{
if (salami.Checked)
{
pizzaTotal += 0.5;
}
}
private void goatsCheese_CheckedChanged(object sender, EventArgs e)
{
if (goatsCheese.Checked)
{
pizzaTotal += 0.5;
}
}
private void chirizo_CheckedChanged(object sender, EventArgs e)
{
if (chirizo.Checked)
{
pizzaTotal += 0.5;
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
finalPizzaTotal = pizzaTotal;
pizzaTotal = 0;
pineappple.Checked = false;
chirizo.Checked = false;
salami.Checked = false;
pepperoni.Checked = false;
goatsCheese.Checked = false;
margeritta.Checked = false;
pepperoni.Checked = false;
hawaiian.Checked = false;
smallPizza.Checked = false;
mediumPizza.Checked = false;
largePizza.Checked = false;
costOfPizza.Text = string.Empty;
}
else if (!checkBox1.Checked)
{
MessageBox.Show(
"If you don't want to order another pizza press " +
" confirm order");
}
}
}
}