I have tried but can't complete
Restaurant Bill Calculator
I have reviewed and read numerous blogs and books on how to perform a step by step approach on how write this program known as C-sharp. As I researched I came across a “youtube” site that teach, the program C-sharp. This site provided me with tremendous insight and I learned a great deal. Subsequent to designing the form, the biggest issue was to figure out how the items appears on the bill and how they are calculated. The idea is to have a running total at the bottom of the calculated items that are added the value total changes, not showing subtotal and tax on the same line. To gain this result I will be using “Classes and Structs” with insight from (“classes and Structs (C# Programming Guide), “) coupled with video explanation on how to code in C-Sharp (15-9C# Restaurant Bill (C# Winforms), 2014)
Using Visual Studio 2010 express, I created a new project windows forms application and titled the project “Restaurant Bill Calculator”. I sized the form window and from the toolbox, selected a combobox. I repeated this step three time then edited the size to, the same value. My next step was form, a toolbox select listbox selecting drag and drop in the form window and size to choose value. Repeating previous step to toolbox select the button control and drag and dropped to the bottom of the form.
In my next step, I selected combobox and modified the properties to change the text name of each combobox to be represented by cmbBeverage, cmbAppettizer, cmbMainCourse and cmbDessert respectively. Opening the string collection editor for each combobox, the display shows the respective members property field for each combobox and auto complete Source set to Custom Source edited to the respective content, so that each selection from one of the four (4) category’s will display the desired choice and value in the app. The listbox is renamed RestaurantBill, next in the design view, I modified the property of the Button to the text name clear and change the display text to clear on the button to “Clear”.
The next step is enter the coding in form, The Struct was identified at the top since it will be used throughout. The struct is the named orders and then in that struct the string for item is declared and the double for price is declared since price a currency.
public partial class Form1 : Form
public struct Orders
public string item;
public double price;
The keyword const is used next to identify the TAX since it will not change. The struct variables are created for the order, and the initial values for subtotal, Tax and total are set to Zero. The bill is declared and the header for the listbox which is Restaurantbill will display at the top with item entries following.
const double TAX = 0.08;
Orders order = new Orders();
static double subtotal = 0;
static double totalTaxes = 0;
static double total = 0;
string finalBill = "CUSTOMER FINAL BILL: \n";
Creating the string for the item and price selection will appear in the Restaurantbill (listbox) in the next. Since the item needs to be identified separately from the price, the split separator control will be used to delimit. Separating the price allow me to isolate it in the order to be converted to price currency and a calculation function applied. The “$” is used as the separator and what appear to left of the “$” is element “0” and what appear to the right , or after the “$” will be element “1”. Using split and n\will allow for each item to be on its own line and each price for the item on a new line. The updateBill calls the custOrder string to action. Using the convert. toDouble takes the text price and converts it to a decimal for currency with two places after the decimal(# -Type Conversion, “)
private void getValues(string custOrder)
order.item = custOrder.Split ('$');
order.price = Convert.ToDouble(custOrder.Split('$'));
finalBill += "Ordered Item: " + order.item + "\nPrice: " + order.price.ToString("C2") + "\n";
The updateBill is defined with calculations to be performed for the subtotal, Tax, and total Using the AddRange for items will allow an array, or list of Multiple items to be added to the RestaurantBill Listbox, each on a new line, prior to the subtotal, tax and total.
private void updateBill()
subtotal += order.price;
total += order.price + (order.price * TAX);
totalTaxes += order.price * TAX;
RestaurantBill.Items.Add("Subtotal: " + subtotal.ToString("C2"));
RestaurantBill.Items.Add("Tax: " + totalTaxes.ToString("C2"));
RestaurantBill.Items.Add("Total: " + total.ToString("C2"));
On the design tab in Visual Studio, I Select all 4 ComboBoxes and in Property, events, I set the value for ‘SelectedIndexChanged’ to ‘dropdownSelection’ which created the event for what happens when the ComboBox drop-down is selected. Using the if/Else -If statements allows for items from each Combobox to be selected and added to listbox.
private void dropdownSelection(object sender, EventArgs e)
if (sender == cmbMainCourse)
else if (sender == cmbAppetizers)
else if (sender == cmbDesserts)
else if (sender == cmbBeverages)
Finally, by clicking the clear bill button on the Design tab, the event to clear upon the button click is declared. The variables in the RestaurantBill listbox to be cleared and the value to reset them to is defined.
private void Clear_Click(object sender, EventArgs e)
subtotal = 0;
totalTaxes = 0;
total = 0;
finalBill = "CUSTOMER FINAL BILL: \n";
Before Launching the Bill calculator app, Debug needs to run which can be achieved by clicking the ‘Start’ function in Visual Studio when the solution is set to debug. If no errors are generated, the app will launch in a new window and the user can performs the functions.Attachments