Purchase Solution

C++ coke machine program

Not what you're looking for?

Ask Custom Question

Create a coke machine program in C++ using if statements and loops.

Think about how a coke machine works and what the code would look like.

We will start by having the users insert their money. Since they can not physically insert the money, we will just ask them how much they wish to insert and we will keep track of how much money they have inserted.

The money insertion will be handled in a Loop. For example, before they start, their total inserted is $0. Let us say that a drink costs $1.00. If they say that they are inserting $0.25 then we will add $0.25 to $0 and tell them to please insert $0.75 more. Then we will ask them how much they are inserting. If they say $0.25, then we add $0.25 to the $0.25 that they have already inserted giving them $0.50. Once they have inserted $1.00, we can give them their drink options. If they have not entered at least $1.00, we will continue to loop so that they can insert more.

Once they have entered enough money, we will ask then what drink they would like. It could be something like this.

Please make your selection
1 = Coke
2 = Pepsi
3 = Dr Pepper

Put the entire main function in a loop so once the transaction is completed, the program will ask if you would like to purchase another drink (y/n). If you choose y for yes, the program will loop again, starting over with $0.00 entered and begin asking the user to enter money. If the user chooses n for no, the loop will exit and an output statement will tell the user what all they have purchased. For example:

You have purchased 1 Coke and 2 Dr. Peppers.

In order to do this, create an array of drinks that have been purchased.

Something like:

Drinks
Coke 0
Pepsi 0
Dr. Pepper 0
Sprite 0
Orange 0

Each time they purchase an item, add one to the number purchased. So, if they purchase a Pepsi, then the number in spot 1 (remember the first spot in an array is 0) would be that number + 1.

Once they have made all of their choices, give them a message saying something like:

You have purchased 2 Cokes.
You have purchased 3 Pepsies.
You have purchased 1 Dr. Pepper.
You have purchased 0 Sprites
You have purchased 9 Orange.

The above numbers will change based on how many of each drink has been purchased.

Purchase this Solution

Solution Summary

This solution includes an example production of a program using C++.

Purchase this Solution


Free BrainMass Quizzes
Javscript Basics

Quiz on basics of javascript programming language.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.