Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ language 1. Item definition The program should start by asking the user to enter the names and prices of two items, and the initial

c++ language
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
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. 5. Buy it again The user can repeat the process of buying an item or quit the program. Remember, if the chosen item is out of stock, the program should inform the user and prompt them to choose another item or quit. 6. Display Requirements Before each purchase, the program should display the items, their prices, and amounts available. After each coin insertion, the program should print the cost of the item and the total inserted coin amount. Example program run (User inputs are highlighted): 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): d Cost: $2.75 Inserted: $1.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): d Cost: $2.75 Inserted: $2.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): q Cost: $2.75 Inserted: $2.25 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): d Cost: $2.75 Inserted: $3.25 Here is your Coke and your change of $0.50. Here are the items available in the machine: 1. Coke - $2.75 (9 available) 2. Snickers - $1.75 (5 available) Which item would you like to buy? (Enter 1 or 2 , or 0 to quit): 2 Cost: $1.75 Inserted: $0.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): d Cost: $1.75 Inserted: $1.00 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): q Cost: $1.75 Inserted: \$1.25 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): q Inserted: $1.50 Insert dollars or quarters (Enter d for dollar, q for quarter, or s to stop): s Cost: $1.75 Inserted: $1.50 You didn't insert enough money. Here is your money back: $1.50 Here are the items available in the machine: 1. Coke - $2.75 (9 available) 2. Snickers - $1.75 (5 available) Which item would you like to buy? (Enter 1 or 2 , or 0 to quit): 0 Thank you for using the Binary Vending Machine! Have a great day! (5 pts) Extra Credit 1 Handle all invalid user input, even data of the wrong type. i.e. Re-prompt the user if they enter "asdf" instead of 1 or 0. (5 pts) Extra Credit 2 Decompose your program into tasks and subtasks using functions. To help you with this, use the following: - Make each function do one thing and one thing only. - No more than 15 lines inside the curly braces of any function, including main(). Whitespace, variable declarations, single curly braces, vertical spacing, comments, output statements, and function headers do not count towards those 15 lines. - Functions over 15 lines need valid justification in comments. - Do not put multiple statements into one line

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

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

Stages of a Relationship?

Answered: 1 week ago