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

What would be a very simple coding solution to question 11 on page 538 in textbo

ID: 3858167 • Letter: W

Question

What would be a very simple coding solution to question 11 on page 538 in textbook Starting Out with Visual C# 4th edition, by Tony Gaddis? I am looking for very basic/elementary level C# coding used for Windows Form App. Any guidance would be greatly appreciated.

Question states:

Create an application that simuluates a soft-drink vending machine. The application should let the user select one of the following soft drinks:

Cola - $1 each, Root beer $1 each, Lemon lime soda $1 each, Grape soda $1.50 each, and Cream soda $1.50 each.

When the application starts, the vending machine will have 20 of each type of soft drink. Each time the user selects a drink, the application should subtract 1 from the quantity of the selected drink. It should also update and display the total amount of sales. If the user selects a drink that is sold out, a message should be displayed indicating so.

In the application's code, create a structure that has fields for the following data:

- Drink Name

- Drink Cost

- Number of Drinks in Machine

The program should create an array of five structure objects. Each element of the array should keep data for a specific type of soft drink.

Explanation / Answer

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

using System.Drawing;

using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1

{

struct Drinks

{

public string drinkname;
public string drinkcost;
public string inventory;

}
public partial class VendingMachine : Form
{
public VendingMachine()
{
InitializeComponent();
}

int grapeTotal = 0;

int lemonTotal = 0;
int rootTotal = 0;
int colaTotal = 0;
int creamTotal=0;
int cokeTotal;
int rootBeerTotal;
int lemonLimeTotal;
int grapeSodaTotal;
int creamSodaTotal;
int EndTotal;


int TotatlCola = 20;
int TotalRoot = 20;
int TotalLemon = 20;
int TotalGrape = 20;
int TotalCream = 20;

string[,] drinkDesc = new string[,] { {"Cola", "1.00", "20"},
{"Root Beer", "1.00", "20"},
{"Lemon Lime", "1.00", "20"},
{"Grape Soda", "1.50", "20"},
{"Cream Soda", "1.50", "20"} };
Drinks Vend;
private void ColaPictureBox_Click(object sender, EventArgs e)
{
Vend.drinkname = drinkDesc[0, 0];
Vend.drinkcost = drinkDesc[0, 1];
Vend.inventory = drinkDesc[0, 2];
TotatlCola = TotatlCola - 1;
{
CokeCountLabel.Text = TotatlCola.ToString();
if (TotatlCola < 1)
{
MessageBox.Show("Sorry No Coke");
}
colaTotal = colaTotal + 1;
cokeTotal = colaTotal * 1;
}
}
private void RootPictureBox_Click(object sender, EventArgs e)
{
Vend.drinkname = drinkDesc[1, 0];
Vend.drinkcost = drinkDesc[1, 1];
Vend.inventory = drinkDesc[1, 2];
TotalRoot = TotalRoot - 1;
{
RootBeerLabel.Text = TotalRoot.ToString();
if (TotalRoot < 1)
{
MessageBox.Show("Sorry No Root Beer");
}

rootTotal = rootTotal + 1;
rootBeerTotal = rootTotal * 1;
}
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void LemonPictureBox_Click(object sender, EventArgs e)
{
Vend.drinkname = drinkDesc[2, 0];
Vend.drinkcost = drinkDesc[2, 1];
Vend.inventory = drinkDesc[2, 2];
TotalLemon = TotalLemon - 1;
{
lemonCountLabel.Text = TotalLemon.ToString();
if (TotalLemon < 1)
{
MessageBox.Show("Sorry No Lemon Juice");
}
lemonTotal = lemonTotal + 1;
lemonLimeTotal = lemonTotal * 1;

}
}
private void GrapePictureBox_Click(object sender, EventArgs e)
{
Vend.drinkname = drinkDesc[3, 0];
Vend.drinkcost = drinkDesc[3, 1];
Vend.inventory = drinkDesc[3, 2];
TotalGrape = TotalGrape - 1;
{
GrapeCountLabel.Text = TotalGrape.ToString();
if (TotalGrape < 1)
{
MessageBox.Show("Sorry No Grape Juice");
}
grapeTotal = grapeTotal + 1;
grapeSodaTotal = Vend.inventory*Vend.drinkcost;

}
}
private void CreamPictureBox_Click(object sender, EventArgs e)
{
Vend.drinkname = drinkDesc[4, 0];
Vend.drinkcost = drinkDesc[4, 1];
Vend.inventory = drinkDesc[4, 2];
TotalCream = TotalCream - 1;
{
CreamCountLabel.Text = TotalCream.ToString();
if (TotalCream < 1)
{
MessageBox.Show("Sorry No Cream Soda");
}
creamTotal = creamTotal + 1;
creamSodaTotal = creamTotal * 1.5;

}
}
private void TotalPictureBox_Click(object sender, EventArgs e)
{
EndTotal = (cokeTotal + rootBeerTotal + lemonLimeTotal + grapeSodaTotal + creamSodaTotal);
TotalLabel.Text=EndTotal.ToString("c");
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote