1,105,427 Community Members

Vending machine

Member Avatar
xclusv-aj
Newbie Poster
6 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

Hi,
i have this assignment and i would like some help with it please. It is my first assignment ever in c++ and it is my first go at writing code for it. Ill post the question and my code so far if anyone could help me get the code correct and working would be really great.

Question:
Your program should operate continuously with a list of drinks and their costs displayed on screen. there should also be a "shutdown" option with a password for a service person to come and re-stock the machine.
Once a user has selected their drink the system should allow them to enter the amount of money they are inserting into the machine. The program should then calculate the amount of change to be returned and subtract one from the number of the drink in the machine. If the user selects a drink which has sold out an appropriate message should be displayed. Some input validation should be carried out on the amount eg. no negative values and no amount larger than $10.
When the "Shutdown" option is chosen the system should report total turnover and number of each drink left in the machine. After a suitable input from the service person the system should then reset the number of drinks back to the initial values and resume normal operation.

Arrays must be used and an expected looping menu-structure.

the drinks are:
coca cola...$1.50....30 (in machine)
sprite........$1.60....30
fanta.........$1.70....30
ginger beer...$1.90.....30
powerade.....$3.50.....20


And this is what i have done so far. It's all mixed up but please forgive me as its my first go. Please help me if you can?

#include <iostream>using namespace std;  int main (){	const int SIZE = 6;    //Array size	char DrinkChoice[SIZE] = { "Coca Cola", "Sprite", "Fanta", "Ginger Beer", "Powerade", "Shutdown"};  //Drink Names	int NumberDrinks[SIZE] = { "30", "30", "30", "30", "20" };  //Number of drinks..other array value are 0. 	double DrinksCost[SIZE] = { "1.50", "1.60", "1.70", "1.90", "3.50" };  //Cost of drink..other array value is 0.	TotalMoney = 0.0;		//money count	int password = 123 do  {	//show user the drink machine menu	cout << "Select choice of Drink" << endl; 	cout << --"Drink Machine Menu"-- << endl;	cout << --"1. Coca Cola"-- << endl;	cout << --"2. Sprite"-- << endl;	cout << --"3. Fanta"-- << endl;	cout << --"4. Ginger Beer"-- << endl;	cout << --"5. Powerade"-- << endl;	cout << --"6. Shutdown"-- << endl;  	//get user response	cin >> UserChoice	cout << DrinksCost	cin >> UserPayment	cout << UserChange		(UserChange = UserPayment - DrinksCost)		( TotalMoney++; )		if (UserPayment <0, >10)		   cout << "This is an error payment.\n"		   cout >> "Please enter payment correctly.\n"		( NumberDrinks - 1 )		if (NumberDrinks = 0)		cout << "This drink is sold out.\n"		cout << "Please pick another.\n"  } until "shutdown" 	cout << "password:"	cin >> UserPassword		if (UserPassword <3, >3)		cout << "access denied.\n"	cout << TurnoverReport		(TurnoverReport = TotalMoney)	cout << NumberDrinks	cin >> "ResetMachine" //show user the drink machine menu	cout << "Select choice of Drink" << endl; 	cout << --"Drink Machine Menu"-- << endl;	cout << --"1. Coca Cola"-- << endl;	cout << --"2. Sprite"-- << endl;	cout << --"3. Fanta"-- << endl;	cout << --"4. Ginger Beer"-- << endl;	cout << --"5. Powerade"-- << endl;	cout << --"6. Shutdown"-- << endl;  system [pause];return 0; }#include <iostream>
using namespace std;


int main ()
{
	const int SIZE = 6;    //Array size
	char DrinkChoice[SIZE] = { "Coca Cola", "Sprite", "Fanta", "Ginger Beer", "Powerade", "Shutdown"};  //Drink Names
	int NumberDrinks[SIZE] = { "30", "30", "30", "30", "20" };  //Number of drinks..other array value are 0. 
	double DrinksCost[SIZE] = { "1.50", "1.60", "1.70", "1.90", "3.50" };  //Cost of drink..other array value is 0.
	TotalMoney = 0.0;		//money count
	int password = 123

do  {
	//show user the drink machine menu
	cout << "Select choice of Drink" << endl; 
	cout << --"Drink Machine Menu"-- << endl;
	cout << --"1. Coca Cola"-- << endl;
	cout << --"2. Sprite"-- << endl;
	cout << --"3. Fanta"-- << endl;
	cout << --"4. Ginger Beer"-- << endl;
	cout << --"5. Powerade"-- << endl;
	cout << --"6. Shutdown"-- << endl;


	//get user response
	cin >> UserChoice
	cout << DrinksCost
	cin >> UserPayment
	cout << UserChange
		(UserChange = UserPayment - DrinksCost)
		( TotalMoney++; )
		if (UserPayment <0, >10)
		   cout << "This is an error payment.\n"
		   cout >> "Please enter payment correctly.\n"
		( NumberDrinks - 1 )
		if (NumberDrinks = 0)
		cout << "This drink is sold out.\n"
		cout << "Please pick another.\n"
	

} until "shutdown"
	
	cout << "password:"
	cin >> UserPassword
		if (UserPassword <3, >3)
		cout << "access denied.\n"
	cout << TurnoverReport
		(TurnoverReport = TotalMoney)
	cout << NumberDrinks
	cin >> "ResetMachine"
	
//show user the drink machine menu
	cout << "Select choice of Drink" << endl; 
	cout << --"Drink Machine Menu"-- << endl;
	cout << --"1. Coca Cola"-- << endl;
	cout << --"2. Sprite"-- << endl;
	cout << --"3. Fanta"-- << endl;
	cout << --"4. Ginger Beer"-- << endl;
	cout << --"5. Powerade"-- << endl;
	cout << --"6. Shutdown"-- << endl;


system [pause];
return 0;

}
Member Avatar
xclusv-aj
Newbie Poster
6 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

sorry..

#include <iostream>
using namespace std;


int main ()
{
	const int SIZE = 6;    //Array size
	char DrinkChoice[SIZE] = { "Coca Cola", "Sprite", "Fanta", "Ginger Beer", "Powerade", "Shutdown"};  //Drink Names
	int NumberDrinks[SIZE] = { "30", "30", "30", "30", "20" };  //Number of drinks..other array value are 0. 
	double DrinksCost[SIZE] = { "1.50", "1.60", "1.70", "1.90", "3.50" };  //Cost of drink..other array value is 0.
	TotalMoney = 0.0;		//money count
	int password = 123;

do  {
	//show user the drink machine menu
	cout << "Select choice of Drink" << endl; 
	cout << --"Drink Machine Menu"-- << endl;
	cout << --"1. Coca Cola"-- << endl;
	cout << --"2. Sprite"-- << endl;
	cout << --"3. Fanta"-- << endl;
	cout << --"4. Ginger Beer"-- << endl;
	cout << --"5. Powerade"-- << endl;
	cout << --"6. Shutdown"-- << endl;


	//get user response
	cin >> UserChoice
	cout << DrinksCost
	cin >> UserPayment
	cout << UserChange
		(UserChange = UserPayment - DrinksCost)
		( TotalMoney++; )
		if (UserPayment <0, >10)
		   cout << "This is an error payment.\n"
		   cout >> "Please enter payment correctly.\n"
		( NumberDrinks - 1 )
		if (NumberDrinks = 0)
		cout << "This drink is sold out.\n"
		cout << "Please pick another.\n"
	

} until "shutdown"
	
	cout << "password:"
	cin >> UserPassword
		if (UserPassword <3, >3)
		cout << "access denied.\n"
	cout << TurnoverReport
		(TurnoverReport = TotalMoney)
	cout << NumberDrinks
	cin >> "ResetMachine"
	
//show user the drink machine menu
	cout << "Select choice of Drink" << endl; 
	cout << --"Drink Machine Menu"-- << endl;
	cout << --"1. Coca Cola"-- << endl;
	cout << --"2. Sprite"-- << endl;
	cout << --"3. Fanta"-- << endl;
	cout << --"4. Ginger Beer"-- << endl;
	cout << --"5. Powerade"-- << endl;
	cout << --"6. Shutdown"-- << endl;


system [pause];
return 0;

}
Member Avatar
Ancient Dragon
Achieved Level 70
27,662 posts since Aug 2005
Reputation Points: 5,234 [?]
Q&As Helped to Solve: 3,039 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
1
 

>>if anyone could help me get the code correct and working would be really great.

You need to state the problem(s) you have with the code and post a few of the error messages your compiler produced. We are not here to do your homework for you.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article