473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

vending machine program

I am seriously stuck and have been working on this for hours and hours and can't figure out my next step....heres the program assignment.

This vending machine dispenses 1. M&Ms ($.65), 2. Chips ($1.16), 3. Peppermint gum ($.28). Your
program should prompt the user to deposit money (i.e. the user needs to type in the amount deposited at
the prompt), select the product, and provide change. Change should be provided in quarters, dimes, and
pennies (you do not have to use nickel and half-dollar coins.) Include a loop to allow the user repeat a
purchase multiple times. If the amount of money entered is insufficient for the purchase the program should
display a message to the user indicating that. The machine must provide “optimum” change – i.e. the
number of quarters and dimes is maximized. For example if $0.36 is the change due, the machine should
return: 1 quarter, 1 dime, and one penny, NOT zero quarters, 2 dimes, and 16 pennies (or any other
combination.)

Here is an example dialogue. User input is indicated in bold font.

Welcome to online vending machine. It serves:
1. M&M ($.65)
2. Chips ($1.16)
3. Peppermint gum ($.28)
Please enter the amount of money deposited (in dollars): 1.50
Please enter your selection: 2
Please pick up your product.
Your change is: 1 quarter, 0 dimes, 9 pennies

Would you like to make another purchase? (y/n) n

All operations should be done with integers. Do NOT use floating point variables in your program.

Use at least the following functions (besides main()):

1. A function to output the prompts and take in user input;
2. A function find_change that computes the number of coins of each of the specified denominations.
The function should accept the money amount and coin denomination and return the number of coins
for that denomination. For example, if find_change accepts $0.31 as an amount of money and
$0.25 as coin denomination (quarters) it should return 1 (one quarter to be returned.) Hint: use integer
division and remainder operator to implement this function.

You should place your program in several files as follows:
• main.cpp – contains main().
• vendlib.h – contains the global constants and function prototypes.
• vendlib.cpp – contains the function definitions for the functions.

Here's what I got so far:

#include <iostream>
#include "vendlib.h"
using namespace std;

int main ()
{
//Printing out welcome message and what the vending machine serves
cout << "Welcome to online vending machine. It Serves: " << endl;
cout << " 1. M&M's ($.65)" << endl;
cout << " 2. Chips ($1.16)" << endl;
cout << " 3. Peppermint gum ($.28)" << endl;
cout << "Please enter the amount of money deposited (in dollars):" << endl;
// assigning variable and getting the input from the user
double money_deposited;
cin >> money_deposited;
cout << "Please enter your selection:" << endl;
// getting the selection number from the user
double product_selection;
cin >> product_selection;
// instructing the user to pick up the product
cout << "Please pick up your product." << endl;
}

I dont't know what to put in the .h and vendlib.cpp files and I can't figure out a way to get the change to print out how the instructor wants...can anyone help me out please!!!
Oct 30 '06 #1
0 5979

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

Similar topics

1
by: pradeepkumar | last post by:
give me the code for vending machine in c++. it has 10 items in a .first display all the items and its cost and its quantityonhand.then ask the customer if he wishes to buy.if yes tell him to select...
9
by: vpascuzzi | last post by:
Here's the deal: I've been working on this little program forever now, and can't seem to get the final little glitches out of it. I am to build a vending machine, using 2 header .h files (one...
7
by: JohnSmith70 | last post by:
Please help I need help with this homework. Its about vending machines, and it should be a piece of cake to you code experts out there. Its about vending machines. Heres the question: It...
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;
1
by: Kunthea | last post by:
I am not that good at programming and I need a little push on how I can start my programming on the vending machine. The basic of the homework is that it displays four snacks and corresponding...
3
by: ismaeel | last post by:
i very need for intrfase of vending machine for netbense sending to email plese
1
by: abil | last post by:
i've already build a program that contain all the price, the change given back to the customer but i dun have no idea which function i should use to do program print report... #include <cstdlib>...
3
by: exospire | last post by:
Hello everyone, I made a program that simulates a vending machine for class. I finally got it to execute without any errors, yet something is not right. I have functions that are being called upon...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.