Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have everything up to the point where i have to display available items. I don't know how to approach this because doing if, else

image text in transcribedimage text in transcribed

I have everything up to the point where i have to display available items. I don't know how to approach this because doing if, else if, and else will make the code longer so I know I'm supposed to use a for loop but I'm not sure how to do so where i can insert the float (item value) and int (stock)

Also for the part right after beneath the highlighted section, I'm not sure how to do this. FOr this part i know I'm supposed to list the starting amount and keep it updated when they insert money. I can do this by using

if (variable x) == d insert 1

if (variable x) == q insert .25

Problem Statement You are asked to build a binary vending machine program in C++. This machine is called "binary" since it sells only two items of user's choice. The names, prices, and initial amount of these items will be defined by the user. Additionally, the vending machine will only accept dollars ($1) and quarters ($0.25) as payment. Thus, the price of each item must be a multiple of 0.25. Detailed Requirements: 1. Item definition The program should start by asking the user to enter the names and prices of two items, and the initial amount of each item available in the machine. The amount of each item should be greater than 0 . The price of each item must be a multiple of 0.25. Re-prompt the user until a valid input is given. 2. Item purchase The user can then choose to buy an item or quit. When the user chooses to buy an item, the program should check if the item is available. If the item is not available, the program should then ask the user to choose a different item or quit, until a valid input is given. Otherwise, the program should prompt the user to insert coins, one at a time. The user can insert either a dollar or a quarter, or they can stop inserting coins. The program should keep track of the total amount inserted by the user and stop prompting as soon as the user has inserted enough money. 3. Payment calculation Once the user has finished inserting coins or decides to stop, the program should determine if the inserted coins are enough to buy the item. If it is, the program should dispense the item and return the change (if any), otherwise return all the inserted coins back to the user. 4. Update Item availability After a successful purchase, the program should update the available amount of the item in the machine. Welcome to the Binary Vending Machine! Enter the name of the first item: Coke Enter the price of the first item (multiple of 0.25 ): 1.30 Invalid input! Enter the price of the first item (multiple of 0.25 ): 2.75 Enter the amount of the first item (great than 0): 5 Invalid input! Enter the amount of the first item (great than 0): 10 Enter the name of the second item: Snickers Enter the price of the second item (multiple of 0.25 ): 1.75 Enter the amount of the second item (great than 0): 5 Here are the items available in the machine: 1. Coke - $2.75 (10 available) 2. Snickers - $1.75 (5 available) Which item would you like to buy? (Enter 1 or 2 , or 0 to quit): 3 Invalid input! Which item would you like to buy? (Enter 1 or 2 , or 0 to quit): 1 Cost: $2.75 Inserted: $0.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): Cost: \$2.75 Inserted: $1.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): Cost: \$2.75 Inserted: $2.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

More Books

Students also viewed these Databases questions