PROJECT
Coffee Machine
Define Menu and Resources
Set menu items with required ingredients and cost for each :espresso, latte, cappuccino
Set initial available resources for water, milk, coffee
Set initial profit to zero
Main Program Loop
While machine is ON:
Ask user: "What would you like? (espresso/latte/cappuccino)"
If user types "off":
Turn machine OFF and exit loop
If user types "report":
Display current resource levels and money earned (profit)
Repeat loop
Else:
Retrieve drink details (ingredients and cost)
Check Resource Sufficiency
For each required ingredient in drink:
If available resource is less than needed:
Print “Sorry, not enough [ingredient]”
Skip to next loop
Otherwise, continue
Process Coins
Ask user how many quarters, dimes, nickels, and pennies were inserted
Calculate the total money received
Check Transaction Success
If money received is at least cost of drink:
Calculate and give any change
Add drink cost to profit
Proceed to make coffee
Else:
Print "Sorry, not enough money. Money refunded."
Cancel transaction and loop again
Make Coffee
Deduct the required ingredients from available resources
Print: "Here is your [drink]. Enjoy!"
Features:
User can order drinks until machine is turned off
Machine checks resource levels before processing any order
Machine processes coin payments, checks if enough was inserted, and returns change if required
Generates a report of available resources and profit anytime requested
Top comments (0)