Problem with Vending Machine Program

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 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)
{
Get_Selection(selection, price);
if(selection < 5) {
money = Get_Money(gCash);
change = Get_Change(money, price);
Write_Change(change);
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
{
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 <<" 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