# McDonalds program using c# 2008

• 03-27-2011
brandonbot
McDonalds program using c# 2008
Alright so I am having trouble programming this it's suppose calculate the total bill along with the amount tendered and change due. It is suppose to be done using methods here are the items along with their prices:

Sandwiches

Hamburger = 1.00;
Double Cheeseburger = 1.59;
McChicken = 1.29;
Cheeseburger = 1.19;
McNuggets10pcs = 3.49;
McNuggets20pcs = 5.99;

Fries

Small French fries = 1.00;
Medium French fries = 1.79;
Large French fries = 2.09;

Drinks

Small = 1.29;
Medium = 1.59;
Large = 1.89;

Caesar = 4.49;
Garden = 4.49;
House = 4.49;

Each heading is in it's own group box I used check boxes for each item and numeric up down scrollbar to select the quantity. I need to program it so that after you select all your food in prints a receipt on another form with total amount tendered and change.

Any help at all would be greatly appreciated.

Thanks:)
• 03-27-2011
VirtualAce
Try first and then come back with a specific problem and we will assist you. The least you could do is lay out your UI given those requirements.
• 03-27-2011
brandonbot
Oh i did sorry heres what i did so far and sorry i'm not really sure what UI means

private void PicCalculate_Click(object sender, EventArgs e)
{
double a1 = 1.00;
double a2 = 0;

double b1 = 1.59;
double b2 = 0;

double c1 = 1.29;
double c2 = 0;

double d1 = 1.19;
double d2 = 0;

double e1 = 3.49;
double e2 = 0;

double f1 = 5.99;
double f2 = 0;

double g1 = 1.00;
double g2 = 0;

double h1 = 1.79;
double h2 = 0;

double i1 = 2.09;
double i2 = 0;

double j1 = 1.29;
double j2 = 0;

double k1 = 1.59;
double k2 = 0;

double l1 = 1.89;
double l2 = 0;

double m1 = 4.49;
double m2 = 0;

double n1 = 4.49;
double n2 = 0;

double o1 = 4.49;
double o2 = 0;

double Total = 0;
double Tax = 0;
double Moneypaid = 0;
double Change = 0;

Total = a1 * a2 + b1 * b2 + c1 * c2 + d1 * d2 + e1 * e2 + f1 * f2 + g1 * g2 + h1 * h2 + i1 * i2 + j1 * j2 + k1 * k2 + l1 * l2 + m1 * m2 + n1 * n2 + o1 * o2;
Tax = Total * 0.13;
Change = Total+Tax-Moneypaid;

Sorry if i posted the code wrong I am kinda knew to this anyway the letter variables represent each item's price as well as quantity. I'm not sure how to proceed and I'm pretty sure I'm not using methods either I'ts not from lack of effort though I have been watching video's but I still don't understand how to use them.
• 03-27-2011
VirtualAce
Two things:
• Use code tags when posting code
• UI - I was assuming you were going to use either Windows Forms or WPF for your user interface. If this is a simple C# program then forget about the UI part.
• 03-27-2011
theoobe
There are many ways of using methods in this situation. Here's one example:

Code:

```private void AddToTotal(ref double total, double item_price, double item_quantity) {     total += (item_price * item_quantity); }```
• 03-27-2011
brandonbot
K thanks I took that and created the other two for calculating tax as well as change due.

private void CalculateTax(ref double Tax, double item_price, double item_quantity)
{
Tax += (item_price * item_quantity*0.13);
}

private void CalculateChange(ref double Tax, double item_price, double item_quantity, double money_paid, double Change)
{
Change += (item_price * item_quantity * 0.13 - money_paid);
}

I'm not sure how to proceed from here though like what do i do with the other code?

It's not recognizing the methods I type out or something when I delete the other calculations everything gets underlined in green.
• 03-27-2011
theoobe
If tax is a fixed rate of 0.13 (13%) for all items, then add the tax to your end total rather than to each item. The results will be the same but with fewer calculations.

Your change method seems odd. Why not subtract money given from money required:

Code:

```private double ChangeRequired(double money_given, double money_required) {     return money_given - money_required; }```
• 03-27-2011
brandonbot
So like this?

private void CalculateTax(ref double Tax, double End_Total)
{
Tax += (End_Total * 0.13);
}

I'm not sure how to proceed now though heres what i have the variables before the methods are underlined in green. How do I make it so it recognizes the two variables as Item price and Item quantity? I really appreciate the help.

double a1 = 1.00;
double a2 = 0;

double b1 = 1.59;
double b2 = 0;

double c1 = 1.29;
double c2 = 0;

double d1 = 1.19;
double d2 = 0;

double e1 = 3.49;
double e2 = 0;

double f1 = 5.99;
double f2 = 0;

double g1 = 1.00;
double g2 = 0;

double h1 = 1.79;
double h2 = 0;

double i1 = 2.09;
double i2 = 0;

double j1 = 1.29;
double j2 = 0;

double k1 = 1.59;
double k2 = 0;

double l1 = 1.89;
double l2 = 0;

double m1 = 4.49;
double m2 = 0;

double n1 = 4.49;
double n2 = 0;

double o1 = 4.49;
double o2 = 0;

}

private void AddToTotal(ref double Total, double item_price, double item_quantity)
{
Total += (item_price * item_quantity);
}

private void CalculateTax(ref double Tax, double End_Total)
{
Tax += (End_Total * 0.13);
}

private double ChangeRequired(double money_given, double money_required)
{
return money_given - money_required;
}

Sorry what's your email maybe if i email you the program it might be easier for you to see what i have to do. I obviously don't want you to do it for me but if you can give me hints i should be able to finish it.
• 03-27-2011
theoobe
At the risk of doing it all for you, I'll get you started as you've pretty much got the Math figured out now.

Code:

```        private void PicCalculate_Click(object sender, EventArgs e)         {             // Gross total             double total = 0;             // Hamburgers             this.AddToTotal(ref total, 1, 0);             // Double Cheeseburger             this.AddToTotal(ref total, 1.59, 7);             // McChicken             this.AddToTotal(ref total, 1.29, 0);             // Cheeseburger             this.AddToTotal(ref total, 1.19, 0);             // And so on.........             // Find out tax             double tax_payable = this.GetTax(total, 0.13);             // Net total rounding off anything over 2 decimal places             double net_total = Math.Round((total + tax_payable), 2);             // Find out how much the customer has given you             double money_given = 20; // let's say \$20 for example             // find out how much change is due             double change_required = this.ChangeRequired(money_given, net_total);             MessageBox.Show("Amount due (pre tax): " + this.ValueToMoneyString(total) +                 "\r\nTax due: " + this.ValueToMoneyString(tax_payable) +                 "\r\nAmount due (post tax): " + this.ValueToMoneyString(net_total) +                 "\r\nMoney given: " + this.ValueToMoneyString(money_given) +                 "\r\nChange given: " + this.ValueToMoneyString(change_required));         }         private void AddToTotal(ref double total, double item_price, double item_quantity)         {             total += (item_price * item_quantity);         }         private double ChangeRequired(double money_given, double money_required)         {             return money_given - money_required;         }         private double GetTax(double total, double tax_rate)         {             return total * tax_rate;         }         private String ValueToMoneyString(double value)         {             // display value in a 0.00 format             return String.Format("{0:0.00}", value);         }```
In this example I have ordered 7 double cheeseburgers.
• 03-27-2011
brandonbot
Alright so I pretty much have it working except like I said I'm using checked boxes for items and numeric up/down scroll bars for quantity. I know the example you showed me you put numbers in for hamburgers ordered and how much cash was given but i'm suppose to make it so you can order any amount of any item and the cash given is random. So I put 0 in for all my quantity variables along with money given now though every time i click calculate everything is equal to zero...
• 03-27-2011
theoobe
What are the variable names of your NumericUpDown controls?? Assuming they are VS designated variable names, use the Value property, eg.

Code:

```// Hamburgers this.AddToTotal(ref total, 1, (double)this.numericUpDown1.Value);```
This assumes that numericUpDown1 is the control used for deciding the quantities of hamburgers you want.

I'm not sure what the purposes of the CheckBoxes are. Are you saying there is 1 CheckBox per item? If so, then this could be used to decide whether to add the calculation for that item to the running total. Again, assuming they are default variable names, use the Checked property, eg:

Code:

```// Hamburgers if (this.checkBox1.Checked)     this.AddToTotal(ref total, 1, (double)this.numericUpDown1.Value);```
This assumes that checkBox1 is the control used for deciding whether to add hamburgers to the running total.

You could go further and disable the corresponding NumericUpDown control depending on the Checked state of the CheckBox.
• 03-27-2011
brandonbot
K so i have all that working but it still says money given is 0...

Should i put a numeric up down control for money given?

Never mind I got it now thank you so much I really appreciate the fact you would help out a complete stranger I may have wasted my entire Sunday but I have it working thanks you.
:)
• 03-29-2011
VirtualAce