You are on page 1of 5

//Programmer: Kathleen Lesavage //Date: 9/19/2013 //Program: Food order form /*Function of this program is to have the user

input quantities in each group box, i.e. radio button, check box and list box. * Program should display cost of beverage in output label. If user enters coupon code 8675309 into the coupon code box, they receive a 10% * discount on the subtotal before the tip and tax are added on. * If the user orders wings w/pizza, the wings are discounted from $6.00 to $4.50, * If they order nachos with tacos, the nachos are discounted from $4.00 to $3.00, if the user orders fries with steak the fries are discounted * from $3.00 to $2.50. * Tax & tip should be declared as a constant at 5.5% and 15% of subtotal. * Variables should be immediately initialized. * Need to utilize the TryParse method for error catching. * Need to us if statements. * Need to use one case/switch statement. * Program should be well commented.*/ using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms;

namespace Final { public partial class Form1 : Form { double grandTotal = 0.00;//holds the value of the total //declare sales tax constant variable to be used throughout the program const double TAX = 5.50 / 100; //declare Tip percentage constant variable to be used throughout the program const double TIP = 15.0 / 100; //declare coupon discount percentage constant variable to be used throughout the program when user enters coupon code public Form1() { InitializeComponent();

} private void radPizza_CheckedChanged(object sender, EventArgs e) { //if radio button pizza is chosen then pizza pic displays if (radPizza.Checked == true) { picP.Visible = true; picS.Visible = false; picT.Visible = false; } } private void radSteak_CheckedChanged(object sender, EventArgs e)

{ //if radio button steak is chosen then steak pic displays if (radSteak.Checked == true) { picP.Visible = false; picS.Visible = true; picT.Visible = false; } } private void radTaco_CheckedChanged(object sender, EventArgs e) { //if radio button tacos is chosen then taco is displayed if (radTaco.Checked == true) { picP.Visible = false; picS.Visible = false; picT.Visible = true; } } private void btnCalc_Click(object sender, EventArgs e) {

double double double double double double double double double count total double double double double double double double double double double double

pizza = 15.00;//cost of 1 pizza steak = 20.00;//cost of 1 steak taco = 10.00;//cost of 1 taco fries = 3.00;//cost of 1 side order fries nachos = 4.00;//cost of 1 side order nachos wings = 6.00;//cost of 1 side order wings entreeBucket = 0;//to hold values to be output drinkBucket = 0;//to hold values to be output costBeverage = 0;//to hold cost of beverages double entreeCt;//entree drinkCt;//drink count totaldouble sidesCt; //side count total subTotal;//holds the value of the subtotal preSubTotalTax;//subtotal before tax added preSubTotalTip;//subtotal before tip added bucket; //holds value of pre tax amount entreeCt;//holds the count of the entree sidesCt;//holds the count of the side sidesBucket = 0;//to hold values to be output couponNum = 8675309; cpDiscount = .10;//the discount percentage cpnCodeDiscount;//bucket to hold discount

int num = 0; double.TryParse(txtBoxQtyEntree.Text, out entreeCt);//collects the users purchase quantity double.TryParse(txtBoxQtySide.Text, out sidesCt);//collects the users purchase quantity double.TryParse(txtBoxQtyBev.Text, out drinkCt);//collects the users purchase quantity

string Beverage;//holds the name of the beverage selected if (radPizza.Checked) { wings = 4.50; entreeBucket = pizza * entreeCt;//calculates and stores the entree order and puts it into the entreeBucket }

if (radSteak.Checked) { fries = 2.50; entreeBucket = steak * entreeCt;//calculates and stores the entree order and puts it into the entreeBucket } if (radTaco.Checked) { nachos = 3.00; entreeBucket = taco * entreeCt;//calculates and stores the entree order and puts it into the entreeBucket } if (ckBoxNachos.Checked) { sidesBucket = nachos * sidesCt;//calculates and stores the side order and puts it into the sidesBucket } if (ckBoxFries.Checked) { sidesBucket = fries * sidesCt;//calculates and stores the side order and puts it into the sidesBucket } if (ckBoxWings.Checked) { sidesBucket = wings * sidesCt;//calculates and stores the side order and puts it into the sidesBucket } if (listBoxBev.SelectedIndex != -1) //drink listbox selection index { //gets the selected beverage then outputs them into string Beverage variable Beverage = listBoxBev.SelectedItem.ToString(); //determines the cost of the beverage switch (Beverage) { case "Soda"://drink choice costBeverage = 2;//drink cost lblOutPutBevTotal.Text = "2.00";//outputs the cost to the label break;

case "Beer"://drink choice costBeverage = 4;//drink cost lblOutPutBevTotal.Text = "4.00";//outputs the cost to the label break; case "Milk"://drink choice costBeverage = 3;//drink cost lblOutPutBevTotal.Text = "3.00";//outputs the cost to the label break; } } drinkBucket = costBeverage * drinkCt;//multiplies the drink quantity with the cost of selected item subTotal = entreeBucket + sidesBucket + drinkBucket;//collect the value of all the buckets to output to the subtotal

bucket = subTotal;//holds the value of the subtotal if (int.TryParse(txtBoxCpn.Text, out num)) { if (num == couponNum) { cpnCodeDiscount = subTotal * cpDiscount; subTotal -= cpnCodeDiscount; } } preSubTotalTax = (TAX * bucket);//calculates the tax and holds in in preSubTotalTax preSubTotalTip = (TIP * bucket);//calculates the tax and holds in in preSubTotalTip grandTotal = (preSubTotalTax + preSubTotalTip + subTotal);//adds the tax, tip and subTotal together and outputs them. txtBoxOutputSubTotal.Text = subTotal.ToString("c");//outputs the subtotal in to the subtotal text box txtBoxOutputTip.Text = preSubTotalTip.ToString("c");//outputs the tip in to the tip text box txtBoxOutputTax.Text = preSubTotalTax.ToString("c");//outputs the tax in to the tax text box txtBoxOutputTotal.Text = grandTotal.ToString("c");//outputs the total in to the total text box

private void btnReset_Click(object sender, EventArgs e) {//resets the form to blank boxes txtBoxOutputSubTotal.Text = " "; txtBoxOutputTax.Text = " "; txtBoxOutputTip.Text = " ";

txtBoxOutputTotal.Text = " "; txtBoxQtyBev.Text = " "; txtBoxQtyEntree.Text = " "; txtBoxQtySide.Text = " "; txtBoxCpn.Text = " "; lblOutPutBevTotal.Text = " "; radPizza.Checked = true; ckBoxNachos.Checked = false; ckBoxWings.Checked = false; ckBoxFries.Checked = false; } private void btnExit_Click(object sender, EventArgs e) { this.Close();//exits the program } private void txtBoxCpn_TextChanged(object sender, EventArgs e) { } private void btnReceipt_Click(object sender, EventArgs e) { MessageBox.Show("Thank you for your order. Your order totaled . \n" + grandTotal.ToString("C")); }

} }

You might also like