using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Restaurant_Bill_Calculator { public partial class RestaurantBillCalculator : Form { public struct Orders { public string item; public double price; } const double TAX = 0.06; //6% tax Orders order = new Orders(); static double subtotal = 0; static double totalTaxes = 0; static double total = 0; string finalBill = "FINAL BILL: \n"; public RestaurantBillCalculator() { InitializeComponent(); } private void getValues(string custOrder) { order.item = custOrder.Split('$')[0]; order.price = Convert.ToDouble(custOrder.Split('$')[1]; Output.Items.Add("Price: " + order.price); finalBill += "Ordered Item: " + order.item + "\nPrice: " + order.price.ToString("C2") + "\n"; updateBill(); } private void updateBill() { subtotal += order.price; total += order.price + (order.price * TAX); totalTaxes += order.price * TAX; { } Output.Items.Clear(); Output.Items.AddRange(finalBill.Split('\n')); Output.Items.Add("Subtotal: " + subtotal.ToString("C2")); Output.Items.Add("Tax: " + totalTaxes.ToString("C2")); Output.Items.Add("Total: " + total.ToString("C2")); } private void RestaurantBillCalculator_Load(object sender, EventArgs e) { } private void dropdownSelection(object sender, EventArgs e) { if (sender == cmbdrinks) getValues(cmbdrinks.SelectedItem.ToString()); else if (sender == cmbappetizers) getValues(cmbappetizers.SelectedItem.ToString()); else if (sender == cmbmaincourses) getValues(cmbmaincourses.SelectedItem.ToString()); else getValues(cmbdrinks.SelectedItem.ToString()); } private void Output_TextChanged(object sender, EventArgs e) { } private void Clear_Click(object sender, EventArgs e) { } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)