Zebra0.com

csharp pizza

To calculate the cost, use the arrays to loop through eeach topping.
It would be nice to lett the user select a file if the default one doesn't exist.

private void CalculateCost()
{
   Double cost = 0;
   // Get the base price for the size.
   if (radSmall.Checked) cost = 9.00;
   else if (radMedium.Checked) cost = 10.00;
   else cost = 12.00;
   // Extra cheese is $1.50.
   if (chkCheese.Checked) cost += 1.50;
   // Add the cost for each topping that is checked.
   for(int i=0;i<toppings.Count;i++)
   {
       if (chkToppings[i].Checked) cost += costs[i];
   }
   // Show the cost with a $ and 2 decimal places.
   lblCost.Text = cost.ToString("$0.00");
}

To do: Read the cost of small, medium, large, and extra chees from a file.

Entire code for Pizza Project

pizzatoppings.txt

End of lesson, Next lesson: Drawing Methods in C#