GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Feb-2008, 06:13
cplus2x cplus2x is offline
New Member
 
Join Date: Feb 2008
Posts: 6
cplus2x has a little shameless behaviour in the past

C++ Candy machine simulation (m0g0l)


Candy Machine Simulation


Write a program to simulate a candy machine.Your machine offers candy for 75 cents, gum for 50 cents, and chips for $1.You should ask the user repeatedly which of the three items she wishes to purchase, or whether she wants to quit.If she chooses to purchase an item, she should be asked to insert the proper amount of money.She should be asked how many dollars, quarters, dimes and nickels she has input.Afterward, a message stating that she purchased a particular item for a particular amount should be printed.Her change, if there is any, should be indicated.If she did not put in enough money, a message should state that no item was dispensed for that reason.


You should assume that she starts with 3 dollars.If she tries to spend more than the amount she has left, a message should be printed and the transaction should be not allowed.Note that this message should be printed as soon as it is known that she is trying to spend more than she has left.For example, this occurs if she chooses an item that costs more than the amount she has left, or if she tries to insert more money than the amount she has left even if the item is affordable.You should print the amount left after each transaction.

When she chooses to quit, a summary of how many of each item she purchased, the total price for them, the overall total spent,the overall change received, and the amount she has left should be printed.

Example


Options:

a.Candy – 75 cents<!--[if !supportLists]-->


b.<!--[endif]-->Gum – 50 cents

<!--[if !supportLists]-->c.<!--[endif]-->Chips – 1 dollar

<!--[if !supportLists]-->d.<!--[endif]-->Quit


Candy Machine: You have $3.00.What would you like to buy?
User: a
Candy Machine: How many dollars?
User: 0
Candy Machine: How many quarters?
User: 2
Candy Machine: How many dimes?
User: 3
Candy Machine: How many nickels?
User: 0


Candy Machine: You purchased candy for 75 cents with 80 cents.Your change is 5 cents.

Candy Machine: You have $2.25.What would you like to buy?
User: a
Candy Machine: How many dollars?
User: 1
Candy Machine: How many quarters?
User: 0
Candy Machine: How many dimes?
User: 0
Candy Machine: How many nickels?
User: 0


Candy Machine: You purchased candy for 75 cents with 1 dollar.Your change is 25 cents.


Candy Machine: You have $1.50.What would you like to buy?
User: c
Candy Machine: How many dollars?
User: 0
Candy Machine: How many quarters?
User: 3
Candy Machine: How many dimes?
User: 3
Candy Machine: How many nickels?
User: 0


Candy Machine: You purchased chips for 1 dollar with 1 dollar and 5 cents.Your change is 5 cents.

Candy Machine: You have $.50.What would you like to buy?
User: b
Candy Machine: How many dollars?
User: 0
Candy Machine: How many quarters?
User: 1
Candy Machine: How many dimes?
User: 0
Candy Machine: How many nickels?
User: 2


Candy Machine: You cannot purchase gum for 50 cents with only 35 cents.

Candy Machine: You have $.50. What would you like to buy?
User: a

Candy Machine: You only have 50 cents left.You do not have enough to purchase candy.


Candy Machine: You have $.50.What would you like to buy?
User: b
Candy Machine: How many dollars?
User: 0
Candy Machine: How many quarters?
User: 1
Candy Machine: How many dimes?
User: 3


Candy Machine: You only have 50 cents left.You cannot spend 55 cents.

Candy Machine: You have $.50.What would you like to buy?
User: d


Thank you.
You purchased:

2 bars of candy for $1.50
1 bag of chips for $1.00

The total you spent was $2.85.
Your total change was $.35.
The total amount you have left is $.50.
--------------------------------------------------------------------------


i need help... i'm confused on what to do....
  #2  
Old 07-Feb-2008, 06:21
cplus2x cplus2x is offline
New Member
 
Join Date: Feb 2008
Posts: 6
cplus2x has a little shameless behaviour in the past

Re: c++ Candy machine simulation(m0g0l)


So far so good... this is what I've made...please bear with me..I'm a newbie when it comes to C++...tsk3x!!

CPP / C++ / C Code:
/*
***Candy Simulation***
***MikhaeL Franko T. Mogol***
*/

#include<iostream.h>


int main()
{
cout<<"******Welcome to Mogol's Candy Shop******\n"
<<"Enter your amount of money\n";

double user_amount;
cin>>user_amount;

cout"You have $"<<user_amount
<<"\nWhat would you like to purchase?"
<< "To select an item, enter\n"
<< "1 for candy\n"
<< "2 for gums\n"
<< "3 for chips\n"
<< "0 to exit\n";

int item;
cin>>item;

the next code, or what to do next... I don't know how... please I beg help need help! Thanks in advance.
Last edited by admin : 07-Feb-2008 at 17:46. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #3  
Old 18-Nov-2010, 08:23
ogultan ogultan is offline
New Member
 
Join Date: Nov 2010
Posts: 2
ogultan is on a distinguished road

Re: C++ Candy machine simulation (m0g0l)


ya that seems like a good idea maybe what you should do it have it automated it to what you want for the machine says what can i get for you? you the customer says hi one bag of cotton candy Machine lists price and he checks off yes or no depending on his budget
  #4  
Old 18-Nov-2010, 08:33
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 969
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: C++ Candy machine simulation (m0g0l)


You will probably want to run everything in a loop. Your loop should look like this:
CPP / C++ / C Code:
bool quit = false;

while(!quit)
{
  // Get a choice from the user
  int choice = /* Read a choice from the user */

  switch(choice)
  {
    case 0:
      quit = true;
      break;

    case 1:
      /* User chose candy so process this request here */
      break;

    case 2:
      /* User chose gum so process this request here */
      break;

    case 3:
      /* User chose chips so process this request here */
      break;
  }
}
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MACRO to detect big / little endian ahbi82 C Programming Language 14 26-Aug-2007 10:33
VS 2008 beta2 's fatal error LNK1112: module machine type 'x64' conflicts with target wincasy MS Visual C++ / MFC Forum 0 29-Jul-2007 07:37
Xchange machine an1 C++ Forum 0 04-May-2007 09:48
apache server cannot access through another machine benluo Apache Web Server Forum 0 13-Jul-2004 19:28

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:29.


vBulletin, Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.