2 Replies - 834 Views - Last Post: 27 April 2017 - 12:21 PM Rate Topic: -----

#1 ColorBlueCoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-April 17

C# Drink Vending Maching Simulator

Posted 24 April 2017 - 11:52 PM

Hello,

This assignment has been discussed many years ago, but I would like some fresh perspective. Here is the link to the problem C# Drink Vending Machine Simulator 2011. I have created a class, an array and accumulator for the total sales. They all work quite nicely. My problem is understanding how to decrement the inventory amount from the value in the array. Should this be done in a method in the class? I am looking for a direction or key word to figure this out. Thank you!

public Form1()
        {
            InitializeComponent();
        }

        ?? = I have no clue; 

        // Declare variables
        decimal sales;          // To hold a sales amount
        decimal total = 0m;    // accumulator for total sales

        // Create an array
        object[,] softDrink = new object[,]
	        {
                {"Cola", 1.0m, 20 },
                {"Rootbeer", 1.0m, 20 },
                {"Lemon Lime", 1.0m, 20 },
                { "Grape Soda", 1.50m, 20 },
	        { "Cream Soda", 1.50m, 20 },

	        };

        private void colaPictureBox_Click(object sender, EventArgs e)
        {
            // Create a Drink object
            Drink cola = new Drink();

            // Set the objects's Name property
            cola.Name = (string)softDrink[0, 0];
            cola.Cost = (decimal)softDrink[0, 1];
            cola.Amount = (int)softDrink[0, 2];      

            if (??)
            {                
                // Get a sales amount
                sales = cola.Cost;

                // Add the sales amount to total
                total += sales;

                // Display the drinks left   
                colaLabel.Text = ??.ToString();
                
                // Display the total sales 
                totalSalesLabel.Text = total.ToString("c");
            }
            else
            {
                MessageBox.Show("Sorry, " + cola.Name + " is sold out.");
            }
        }
:code:

This post has been edited by modi123_1: 25 April 2017 - 06:47 AM
Reason for edit:: Please use the [code] button in the editor..


Is This A Good Question/Topic? 0
  • +

Replies To: C# Drink Vending Maching Simulator

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13493
  • View blog
  • Posts: 53,902
  • Joined: 12-June 08

Re: C# Drink Vending Maching Simulator

Posted 25 April 2017 - 06:49 AM

I would figure you know what option is being pushed from the UI, right? Use that to get the index position in the array, and then decrement the amount in the array at that index.
Was This Post Helpful? 1
  • +
  • -

#3 ColorBlueCoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-April 17

Re: C# Drink Vending Maching Simulator

Posted 27 April 2017 - 12:21 PM

View Postmodi123_1, on 25 April 2017 - 06:49 AM, said:

I would figure you know what option is being pushed from the UI, right? Use that to get the index position in the array, and then decrement the amount in the array at that index.


I apologize for not getting back to you sooner. I was taking my final exams. Thank you!!! Your recommendation worked beautifully. I was then able to write some class methods to total the count and amount. In addition, your suggestion was on the exam. :bigsmile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1