Vending Machine Simulator

The program should create an array of five structures. Each time the program runs, it should read the data from the input file ("DrinkMachineInventory.txt") and then enter a loop that performs the following steps:

Display the list of drinks, cost, and the number of drinks in the machine.
The user should be allowed to either quit the program or pick a drink. If the user selects a drink, he or she will next enter the amount of money that is to be inserted into the drink machine. The program should display the amount of change that would be returned and subtract one from the number of that drink left in the machine. If the user selects a drink that has sold out, a message should be displayed. The loop then repeats. When the user chooses to quit the program it should display the total amount of money the machine earned.

Lost have no idea what to do.

#include <iostream>
#include <string>
#include <cstdlib>
#include <fstream>

using namespace std;

const int Num_Name = 5;
const int Max_SIZE = 20;

struct DrinkInfo
{
char name[Max_SIZE];
double cost;
double NumDrinks;
double change;
double NewNumDrinks;
double MachineTotal;
};

bool getDrinks(DrinkInfo [], double);
void displayDrinks(const DrinkInfo, double);
bool myDrinks(DrinkInfo [], char , int );


int main (int argc, char *argv[])
{
DrinkInfo myDrinks[5];

if (!getDrinks)
{
cout << "Trouble reading from input file.";
cout << "\nExiting...";
system("PAUSE");
return EXIT_FAILURE;
}

system("PAUSE");
return EXIT_SUCCESS;
}
void displayDrinks(const DrinkInfo drinks[], int size)
{
for (int i=0; i<size; i++)
{
cout << "Name: " << drinks[i].name << endl;
cout << "Cost: " << drinks[i].cost << endl;
cout << "Number of drinks in the machine: " << drinks[i].NumDrinks << endl;
cout << endl;
}
bool myDrinks(DrinkInfo drinks[], char temp, int Max_SIZE,)
{
ifstream inFile;
char temp[MAX_SIZE];
inFile.open("DrinkMachineInventory.txt");
if (!inFile)
}
{
return false;
}
else
{
for (int i=0; i<size; i++)
{
inFile.getline(drinks[i].name, MAX_SIZE, ',');

inFile.getline(temp, MAX_SIZE, ',');

drinks[i].cost = atoi(temp);

inFile.getline(temp, MAX_SIZE, '\n');

drinks[i].NumDrinks = atoi(temp);
}
return true;
}
return 0;
}
else
{
cout <<"Pick a drink" << endl;
cin >> name;
cout << "The drink you chose cost:" << cost << endl;
cout <<"Enter amount of money" << endl;
cin >> userAmount;
}

if (userAmount < 0)
{
cout << "You entered a negative amount" << endl;
cout << "Please enter a positive number" << endl;
}
if (userAmount < cost )
{
cout << "You do not have enough money" << endl;
cout << "Please enter the correct cost" << endl;
}
if (userAmount > cost)
{
change = userAmount - cost
cout << "Your change:" << change << endl;
NewNumDrinks = NumDrinks - 1
cout << "Number of Drinks left:" << NewNumDrinks << endl;
}
if (NumDrinks = 0)
{
cout << "This drink has sold out:" << name << endl;

}

MachineTotal = userAmount
cout << "The machine earned" << MachineTotal << endl;
}

Topic archived. No new replies allowed.