You have invented a vending machine capable of deep frying twinkies. Write a pro
ID: 3531675 • Letter: Y
Question
You have invented a vending machine capable of deep frying twinkies. Write a program to simulate the vending machine. It costs $ 3.50 to buy a deep- fried twinkie, and the machine only takes coins in denominations of a dollar, quarter, dime, or nickel. Write code to simulate a person putting money into the vending machine by repeatedly prompting the user for the next coin to be inserted. Output the total entered so far when each coin is inserted. When $ 3.50 or more is added, the program should output Enjoy your deep- fried twinkie along with any change that should be returned. Use top- down design to determine appropriate functions for the program.
Explanation / Answer
#include using namespace std; void twinkie(); bool good(int); const int TWINKIE_COST = 350; const int DOLLAR = 100, QUARTER = 25, DIME = 10, NICKEL = 5; int main() { //use a loop to repeat the twinkie machine char ans; do { //use the machine to get a twinkie. twinkie(); cout > ans; }while (ans == 'y' || ans == 'Y'); return 0; } //twinkie vending machine void twinkie() { //declare all variables needed //initialize where necessary int total_coins = 0, coin, change; //a loop to take coins up to 350 do { //prompt user to enter coin cout > coin; //validate coin value. make a bool function to validate if (good(coin)) { total_coins += coin; //total up coins coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.