soft drink Vending machine program


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: soft drink Vending machine program

  1. #1
    Join Date
    Apr 2006
    Posts
    5

    soft drink Vending machine program

    //I need help to write this program I am fairly new to C+ and I need the program to use struct. Please help me get started. I don't know where to start!!!!!
    Write a program that simulates a soft drink machine. The program should use a structure that stores the following information:

    Drink name
    Drink cost
    Number of drinks in machine

    The program should create an array of five structures. The elements should be initialized with the following data:

    Drink Name Cost Number in Machine
    Coke .75 30
    Water .75 10
    Sprite .50 50
    MountainDew .80 25
    MinuteMaid .80 20

    Each time the program runs, it should enter a loop that does the following:

    1) Display a list of drinks on the screen
    2) Allow the user to either quit or pick a drink
    3) If the user picks a drink, he or shill will then enter the amount of money to be inserted into the machine
    4) The program should then display the amount of change that would be returned and update the number of drinks still in machine. If the user has not entered enough money, the program should display how much more should be entered to complete the sale.
    5) If the user selects a drink that has been sold it, a message should be displayed

    This loop should continue until the user says Quit. When the user quits, it should display the total amount of money earned by that machine (based on how many drinks were bought).

    The program should not accept money amounts less than 0 or greater than $1.00

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    start with the structs, then create the loops and functions, and finally create the main program. We're here to help you help yourself, not write your homework assignments.
    Danny Kalev

  3. #3
    Join Date
    May 2009
    Posts
    1

    Smile Need help

    I do have the same assignment as it is written in up part,i wrote the code just i have a problem. I don't know how to write a code for machine that shows how many drinks are left in the machine? I have 5 type of drink and each has a quantity of 20 in the machine. I have to calculate the amount drink left in the machine after everytime purchase of that drink.

    can u please give me some hints???

    thanks

  4. #4
    Join Date
    Dec 2003
    Posts
    3,366
    somehow, work these ideas in:

    int sprites_left = 6; //initialize: how many sprites are in the machine?

    ....
    if(user trys to buy sprite && sprites_left == 0)
    cout << "oh noes, out of sprites, buy something else or go away\n";

    ....

    if (user buys a sprite)
    sprites_left--;

    you have to do that for each drink type though, so you might do this:

    enum
    {
    sprite,
    beer,
    coke,
    pepsi,
    water,
    max_drink_types

    };

    int drinks_left[max_drink_types];
    drinks_left[coke] = 3; //initialize each one
    drinks_left[beer] = 11;
    ...

    and as above:
    case(what_did_he_buy)
    beer:
    drinks_left[beer] --;
    ....
    etc.

    same idea but a little more organized.

  5. #5
    Join Date
    Aug 2009
    Posts
    1

    Same Question

    Hi All,

    Can anyone help me with the above question, when user selects a drink then how do we code that in c# giving him the option of drinks????

    thanks

  6. #6
    Join Date
    Nov 2003
    Posts
    4,118
    Perhaps you want to post this question on the .Net forum: http://forums.devx.com/forumdisplay.php?f=120
    Danny Kalev

Similar Threads

  1. Long, basic Java Question.
    By Tom in forum Java
    Replies: 0
    Last Post: 03-18-2002, 10:25 AM
  2. Please help with running executable vb program.
    By Gordon Reichhardt in forum VB Classic
    Replies: 2
    Last Post: 01-08-2002, 10:06 AM
  3. Replies: 0
    Last Post: 03-18-2001, 11:33 AM
  4. Replies: 0
    Last Post: 05-12-2000, 10:40 AM
  5. Java Virtual Machine
    By Raj in forum Java
    Replies: 2
    Last Post: 04-14-2000, 07:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center