Problem with Vending Machine Program


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Problem with Vending Machine Program

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    2

    Problem with Vending Machine Program

    Please help me to complete the program..i already got stucked..thanks in advance..for information i'm using dev-cpp software

    Assumptions:

    1. The vending machine will use only coins of following denominations. 10 sen, 20 sen, and 50
    sen.

    2. The customer will make a selection for the item, and insert the coins only after selection. This
    way, once the machine counts coins for amount exceeding the price of the item, the selected
    item will be vended.

    3. The machine will not accept more that RM 2.00.

    4. At no point will the machine run out of coins to give change to the customer.

    5. To save on the number of coins to be given as change, you will start from the highest 50 sen
    to the lowest denomination (10 sen) while computing the denominations to be given as change

    Global Variables:
    REMINDER: You are not allowed to add global variable
    1. Constant identifier that represents the index of drinks to be sold by the vending machine are
    as follows:
    gPrice and gDrinks.
    const int ICE_LEMON_TEA = 0;
    const int NESCAFE = 1;
    const int HORLICK = 2;
    const int TEA = 3;
    2. Array that stores the price of Teh Tarik, Nescafe, Horlick and Teh 0 respectively.
    float gPrice[4] = {1,1.1,1.2,.9};
    3. Array that stores the number of cup sold for Teh Tarik, Nescafe, Horlick and Teh 0 repectively.
    int gDrinks[4] = {0, 0, 0, 0};
    4. Array that stores the nomination quantity of 10 sen, 20 sen and 50 sen dispensed to the
    customer.
    int gCoins[3] = {0, 0, 0};
    5. Variable that stores the money received by the customer.
    float gCash = 0;

    /****************************************************************************
    ****************************************************************************
    VENDING MACHINE SYSTEM
    *****************************************************************************
    *****************************************************************************/


    #include <cstdlib>
    #include <iostream>
    #include <iomanip>
    using namespace std;
    const int ICE_LEMON_TEA = 0;
    const int NESCAFE = 1;
    const int HORLICK = 2;
    const int TEA = 3;
    float gPrice[4] = {1,1.1,1.2,.9};
    int gDrinks[4] = {0, 0, 0, 0};
    int gCoins[4] = {0, 0, 0, 0};
    float gCash = 0;
    void Write_Menu();
    void Get_Selection(int&, float&);
    float Get_Money(float&);
    float Get_Change(float, float);
    void Write_Change(float);
    void Write_Report_Cash_Out(const int c oins[]);
    void Write_Report_Drink s(const int drink s[]);
    void Write_Report_Cash_In();
    int main(int argc, char *argv[])
    {
    int selection=0;
    float price;
    float money;
    float change;
    while(selection != 6)
    {
    Write_Menu();
    Get_Selection(selection, price);
    if(selection < 5) {
    money = Get_Money(gCash);
    change = Get_Change(money, price);
    Write_Change(change);
    }
    }
    system("PAUSE");
    return EXIT_SUCCESS;
    }
    void Write_Menu()
    {
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
    cout <<" "<<endl<<endl;
    cout <<" ***************************************** "<<endl;
    cout <<" * * "<<endl;
    cout <<" * VENDING MACHINE * "<<endl;
    cout <<" * * "<<endl;

    cout <<" * Teh Tarik\t- "<<gPrice[ICE_LEMON_TEA]<<"\t- Press 1 * "<<endl;
    cout <<" * Nescafe\t- "<<gPrice[NESCAFE]<<"\t- Press 2 * "<<endl;
    cout <<" * Horlick \t- "<<gPrice[HORLICK]<<"\t- Press 3 * "<<endl;
    cout <<" * Teh 'O'\t- "<<gPrice[TEA]<<"\t- Press 4 * "<<endl;
    cout <<" * Print Report\t\t- Press 5 * "<<endl;
    cout <<" * Terminate\t\t- Press 6 * "<<endl;
    cout <<" * * "<<endl;
    cout <<" ***************************************** "<<endl;
    }
    void Get_Selection(int& selection, float &price)
    {
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
    cout <<" Please enter your selection."<<endl;
    cout <<" Then press Enter. "<<endl;
    cout <<" Your selection > ";
    cin >>selection;
    switch(selection)
    {
    case 1:
    cout <<" You chose Teh Tarik - "<<ICE_LEMON_TEA<<endl;
    price = gPrice[ICE_LEMON_TEA];
    break;
    case 2:
    cout <<" You chose Nescafe - "<<NESCAFE<<endl;
    price = gPrice[NESCAFE];
    break;
    case 3:
    cout <<" You chose Horlick - "<<HORLICK<<endl;
    price = gPrice[HORLICK];
    break;
    case 4:
    cout <<" You chose Teh O - "<<TEA<<endl;
    price = gPrice[TEA];
    break;
    case 5:
    Write_Report_Cash_Out(gCoins);
    Write_Report_Drinks(gDrinks);
    Write_Report_Cash_In();
    price = 0;
    break;
    case 6:
    price = 0;
    break;
    default:
    price = 0;
    cout<<" You must enter a selection between 1 and 6. Thank You!"<<endl<<endl;
    }
    }
    float Get_Money(float& cash)
    {
    float money;
    cout <<" Please enter the RM amount"<<endl;
    cout <<" you are spending. Then pres s Enter."<<endl;
    cout <<" Your spending > ";
    //Get money from the customer and to make sure
    //it does not ex ceed Rm 2.00
    //Add the money to cash
    return money;
    }
    float Get_Change(float money, float price)
    {
    float change;
    //formula to calculate the change to be given
    //to the customer
    return change;
    }

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Describe where you are stuck and what your thoughts are about why you are stuck.

  3. #3
    Join Date
    Mar 2009
    Posts
    2
    actually this is the upcomplete program, what i need is to develop process for get the money and get the balance, it actually have in the assumption taht i already gave

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    How do you think you can carry out these functions? What is the plan of attack ("algorithm") that you have in mind?

Similar Threads

  1. soft drink Vending machine program
    By divagoddess in forum C++
    Replies: 5
    Last Post: 08-14-2009, 03:12 PM
  2. Replies: 3
    Last Post: 03-06-2008, 07:57 AM
  3. Memory problem with Borland C3.1
    By AZ1699 in forum C++
    Replies: 11
    Last Post: 11-16-2007, 12:23 PM
  4. Replies: 0
    Last Post: 09-12-2007, 07:50 AM
  5. Please help with running executable vb program.
    By Gordon Reichhardt in forum VB Classic
    Replies: 2
    Last Post: 01-08-2002, 10:06 AM

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