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....

/*
***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 dont know how... pls i beg help!! need help!!!... thanks in advance... pls help me!!!

/*
***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 dont know how... pls i beg help!! need help!!!... thanks in advance... pls help me!!!

you can if statements

int balance;
if (item=1){
balance=user_amount-0.75;
}

that should get you started

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.