Can anyone help me. I have a c++ project to do. The program must simulate a vending machine. I will post what i have so far. a data file must be hardcoded into it which provides the different drinks.

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

using namespace std;

const int SIZE=54;

int cans;

typedef string vendingArray[SIZE];


int main()
{
	
	int cans;
	
	int choice;
	
	int balance=0;

	int dollar=0;

	int half=0;

	int nickle=0;

	int dime=0;

	int quart=0;

	int cent=nickle+dime+quart+half;

	vendingArray sodaMachine;

	
	cout <<"=======================================""\n";
	cout <<"Welcome To The Drink Vender""\n";
	cout <<"This program simulates a vending machine""\n";
	
	ifstream infile;

	infile.open("machine.txt");

	if(!infile)
	{
		cout <<"Error: Data Cannot Be Opened";
		exit( EXIT_FAILURE );
	}

	else
	{
		infile >> cans;

		for(int i=0; i < cans; i++)
		{
			infile >> sodaMachine[i];

			cout << sodaMachine[i] << "\n";
		}
	}

	infile.clear();
	
	infile.close();



	
	
	
	cout <<"The current balance is\t" <<dollar << " dollars and "<< cent <<" cents "<<endl;
	cout <<"Please choose from one of these options"<<endl;
	cout <<"\n";

	
	cout << "\n" <<"Enter a number to choose an option:\t";
    cin >> choice;
    
	if (choice==5)
    { 
		balance +=5; 
	}
    if (choice==10)
    { 
		balance +=10; 
	}
    if (choice==25)
    { 
		balance +=25; 
	}
	if (choice==50)
    { 
		balance +=50; 
	}
	if (choice==100)
    { 
		balance +=100; 
	}
	if (choice==45)
    { 
		balance -=45; 
	}
	if (choice==50)
    { 
		balance -=50; 
	}
    if (choice==55)
    { 
		balance -=55; 
	}
    if (choice==60)
    { 
		balance -=60; 
	}
    if (choice==70)
    { 
		balance -=70; 
	}
	if (choice==85)
    { 
		balance -=85; 
	}
return(0);
}

Uhm.. I don't see your question anywhere? :)

Uhm.. I don't see your question anywhere? :)

When I run what i have so far, it prints out my introduction. i cant figure out how to hardcode my data file either. also i am supposed to use at 7 different functions in this program and am unsure as to what types of i would need.

When I run what i have so far, it prints out my introduction. i cant figure out how to hardcode my data file either. also i am supposed to use at 7 different functions in this program and am unsure as to what types of i would need.

Hardcoding your drinks shouldn't be that hard.
Why dont you just make a big string with them? I mean, thats a simple way to do it, but theres many options :)

Hardcoding your drinks shouldn't be that hard.
Why dont you just make a big string with them? I mean, thats a simple way to do it, but theres many options :)

Im also not sure if i set up my array the right way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.