Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone please give me a real step-by-step on how to accomplish this solutio

ID: 3559757 • Letter: C

Question

Can someone please give me a real step-by-step on how to accomplish this solution? I have followed the other solutions on this subject with no success as of yet. This is using Visual Studio & programming in C#. Thanks.

a. A market sells eggs at $4.9 per dozen, milk at $3.25 per quart, and bread at $5.12 per loaf. Use a combo box to allow the user to select an item, and a text box for the user to input the quantity desired. Include an Order button to allow the user to order the specified quantity of the selected item. When the user presses the Order button, a description and the total cost of the order should appear in the form. b. Allow the user to order more than one type of food. Each time the user presses the order button, describe the purchase. Add a Total button, and when the user presses this button, display the total prices of all items ordered.

Explanation / Answer

I'll assume that you're working with Visual Studio 2010 or similar, and that you have basic knowledge in C# and in C# GUI. If that's not the case, you can PM me fo full details so we don't crowd it here. Also, I'll be doing things programmatically even though you can do some of this stuff via the designer interface and the properties window.
WARNING - DO NOT COPY PASTE AS IS AND EXPECT THIS TO WORK, there are steps you need to do beforehand, and LOOK FOR THESE METHODS IN YOUR CODE AND ADD THE EXTRA IMPLEMENTATION TO WHAT4S ALREADY THERE - do not replace stuff and to not add all content without understanding it first. for instance, InitializeComponent() in the Form constructor needs to stay as is and be there only once.

Drag and drop a label, a combobox, a textbox and a button onto your form.

the system will call them label1, combobox1, textbox1 and button1 by default.

go to the form constructor, set your label text to blank since we haven't ordered yet, set your button1 text to Order, and add the items for the combobox in it so that [eggs, milk, bread] show up on the combobox when you run your application. Once we fill it, we set the combobox selected index to 0 otherwise it shows us a blank as the default, and our items only show up when you click the combobox and they drop down. This way, the first itm (eggs) shows up bydefault

public Form1()

{

InitializeComponent();

this.label1.Text = "";

this.button1.Text = "Order";

this.comboBox1.Items.Add("Eggs by dozen");

this.comboBox1.Items.Add("Milk by quart");

this.comboBox1.Items.Add("Bread by loaf");

this.comboBox1.SelectedIndex = 0;

}

Next, the textbox is just about entering the quantity you want - you just need to convert the text into an integer when you get it, since it's a quantity,
Then when you click the button, you display the order ) the order being ItemPrice * quantity. To generate the button click event, you can just go to the form GUI in designer mode, and double click button1. Then a method is generated for you in code and you have to add the implementation like so:

private

void button1_Click(object sender, EventArgs e)

{

int choice = this.comboBox1.SelectedIndex;

int quantity = Int32.Parse(this.textBox1.Text);

double price = 0;

switch (choice)

{

case 0:

// the user ordered eggs

price = 4.9 * quantity;

this.label1.Text = "You ordered Eggs for a total of $" + price;

break;

case 1:

// the user ordered milk

price = 3.25 * quantity;

this.label1.Text = "You ordered Milk for a total of $" + price;

break;

case 2:

// the user ordered bread

price = 5.12 * quantity;

this.label1.Text = "You ordered Bread for a total of $" + price;

break;

}

}