473,473 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

program to simulate a soft drink machine

16 New Member
Write a program that simulates a soft drink machine. The program should use a structure that stores the following information:

Drink name
Drink cost
Number of drinks in machine

The program should create an array of five structures. The elements should be initialized with the following data:


Drink Name Cost Number in Machine
Coke .75 20
A_and_W .75 20
Sprite .75 20
Shasta .80 20
MinuteMaid .80 20

Each time the program runs, it should enter a loop that does the following:

Display a list of drinks on the screen
Allow the user to either quit or pick a drink
If the user picks a drink, he or shill will then enter the amount of money to be inserted into the machine
The program should then display the amount of change that would be returned and update the number of drinks still in machine. If the user has not entered enough money, the program should display how much more should be entered to complete the sale.
If the user selects a drink that has been sold it, a message should be displayed

This loop should continue until the user says Quit. When the user quits, it should display the total amount of money earned by that machine (based on how many drinks were bought).

The program should not accept money amounts less than 0 or greater than $1.00





this is what i have so far....

struc Machine
{
string Drink_name;
int cost;
int Num_of_drinks;
};

struct Machine Drink[4];

drink[0]= {"coke", .75, 20};
drink[1]= {"A and W", .75, 20};
drink[2]={"sprite", .75, 20};
drink[3] ={"shasta", .80, 20};
drink[4]= {"minute maid", .80, 20};

QUESTION: i dont know if am initializing the variables correctly. so if someone could please provide some insight on this. thanks.
Dec 10 '06 #1
4 9802
horace1
1,510 Recognized Expert Top Contributor
you cannot assign to an array element so
Expand|Select|Wrap|Line Numbers
  1. Drink[0]= {"coke", .75, 20};
  2.  
you can initialise the array elements when you define it
Expand|Select|Wrap|Line Numbers
  1. struct Machine
  2. {
  3. string Drink_name;
  4. float cost;
  5. int Num_of_drinks;
  6. };
  7.  
  8. struct Machine Drink[]={{"coke", .75, 20},{"A and W", .75, 20},
  9.                         {"sprite", .75, 20},{"shasta", .80, 20},
  10.                         {"minute maid", .80, 20}};
  11.  
Dec 10 '06 #2
queenma7
16 New Member
you cannot assign to an array element so
Expand|Select|Wrap|Line Numbers
  1. Drink[0]= {"coke", .75, 20};
  2.  
you can initialise the array elements when you define it
Expand|Select|Wrap|Line Numbers
  1. struct Machine
  2. {
  3. string Drink_name;
  4. float cost;
  5. int Num_of_drinks;
  6. };
  7.  
  8. struct Machine Drink[]={{"coke", .75, 20},{"A and W", .75, 20},
  9.                         {"sprite", .75, 20},{"shasta", .80, 20},
  10.                         {"minute maid", .80, 20}};
  11.  
thanks that was helpful.
QUESTION: i ask the user to input how much money they will enter into the machine, then am suppose to give back to them the change or if they didnt put enough money give back how much to put in.

first i did a loop for the menu choice. then i asked the user to pick a drink.
if they enter 1 they picked coke. but what i dont know is how to use the amount the user inputs and subract the cost of coke from this.

can i say.....
if (moneyinput < .75)
cout << .75 - moneyinput << endl

to give back change to the user, can i say.......
if (moneyinput > .75)
cout << moneyinput - .75 << endl

i dont think i can do this but how else can i access the cost of coke that is in my array?
Dec 10 '06 #3
DeMan
1,806 Top Contributor
Drink[0].cost; //for coke

Don't forget to check Drink[0].num_of_Drinks (to make sure you have drink there)
Dec 10 '06 #4
queenma7
16 New Member
THIS IS WHAT I HAVE SO FAR................


#include <iostream>
#include <string>
#include <cmath>
using namespace std;

struct Machine
{
string Drink_name;
float cost;
int num_drinks;
};
struct Machine drink[] = {{"coke", .75, 20}, {"A and W", .75, 20}, { "sprite", .75, 20},
{"shasta", .80, 20}, {"minute maid", .80, 20}};
int main()
{
int menu_choice;
float moneyin;
float moneyout;
float temp;
while (menu_choice != 6)
{
cout <<"which drink would you like to buy:" << endl;
cout <<"1-coke" << endl;
cout <<"2-A and W" << endl;
cout <<"3-sprite" << endl;
cout <<"4-shasta" << endl;
cout <<"5-minute maid" << endl;
cout <<"6-Quit\n " << endl;
cin >> menu_choice;
if (menu_choice == 1)
{
cout << "enter money to inserted into machine between 0 and $1.00" << endl;
cin >> moneyin;
while (moneyin < drink[0].cost)
{
cout <<"enter" << (drink[0].cost<< endl;
cin >> moneyout;
temp =
if (temp == drink[0].cost)
cout <<"great" << endl;
}
if (moneyin > drink[0].cost)
cout <<" your change is:" << (moneyin - drink[0].cost) << endl;
}
}
return 0;
}


QUESTION: i the user doesnt put in enough money, i have to tell them the right amount to put in that is the difference of drink[0] - moneyin. i have to do this until they put in the right amount. so if they need to put in 50cents they only put .15 i have to tell them to put in .35 cents, if the only put in 10, i have to tell them to put in 25cents until the right amount is reached. i tried a while loop but i think am doing it wrong. please offer some guidance.
Dec 11 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

383
by: John Bailo | last post by:
The war of the OSes was won a long time ago. Unix has always been, and will continue to be, the Server OS in the form of Linux. Microsoft struggled mightily to win that battle -- creating a...
10
by: An Ony | last post by:
Hi, I made a console program in C# and it works for me. Now I sent it to someone else and he can't run it. Program error or something. His OS is in Swedish. What could this be? Does he have to...
3
by: 31337one | last post by:
Hello everyone, I am using a python script as a way to test another program that I have written in C++. The program cannot be altered. It needs to stay the way it is. I need to simulate a few...
3
by: monicaw811 | last post by:
I can't figure out what is a constant. How do you start this? Below is info I was given and what I started (not much I know). ...
1
by: raishi | last post by:
I am trying to figure out how to make a simple slot machine program in VBScript that starts by prompting and collecting the desired number of slot machine spins to simulate simulates the spins:...
3
by: partialprogressive | last post by:
I have a c++ program that runs with interactive text input and output with stdin and stdout. I want to change it to run from a server, with the interaction via web browser. It is not practical to...
6
by: Crooter | last post by:
Hello colleagues, Could anybody tell me if there are existing open-source solutions to extract the program tree using a program source code? I'm aware that GCC has program flow information and...
2
by: nb999 | last post by:
Hello Friends, I was trying to simulate a vending machine using perl just as a fun project. Heres the code I wrote: #!/usr/bin/perl $wt = $ARGV;
0
by: paulvz882 | last post by:
comprimes de acomplia en France commander acomplia en ligne aucune prescription acomplia canada soft en ligne +++ PERTE DE POIDS +++ PERTE DE POIDS +++ PERTE DE POIDS +++ + ACHETER DU ACOMPLIA...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.