Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You have invented a vending machine capable of deep frying twinkies. Write a pro

ID: 3679014 • 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. Allow the buyer to purchase again if desired.

IMPLEMENTATION: Use at least two functions: one to accept money and one to make change. Validate the denominations.

WELCOME TO TWINKIE VENDING MACHINE

TWINKIES are $3.50 each.

Please insert coins:

n - Nickel

d - Dime

q - Quarter

D - Dollar

A fried TWINKIE costs $3.50. You have inserted $0.00.

Next coin: n

Please insert coins:

n - Nickel

d - Dime

q - Quarter

D - Dollar

A fried TWINKIE costs $3.50. You have inserted $0.05.

Next coin: D

Please insert coins:

n - Nickel

d - Dime

q - Quarter

D - Dollar

A fried TWINKIE costs $3.50. You have inserted $1.05.

Next coin: D

Please insert coins:

n - Nickel

d - Dime

q - Quarter

D - Dollar

A fried TWINKIE costs $3.50. You have inserted $2.05.

Next coin: D

Please insert coins:

n - Nickel

d - Dime

q - Quarter

D - Dollar

A fried TWINKIE costs $3.50. You have inserted $3.05.

Next coin: q

Please insert coins:

n - Nickel

d - Dime

q - Quarter

D - Dollar

A fried TWINKIE costs $3.50. You have inserted $3.30.

Next coin: q

You have inserted $3.55

Enjoy your deep-fried TWINKIE. Your change is $0.05

Would you like to purchase another?

Explanation / Answer


#include<iostream>
#include <iomanip>
using namespace std;

float buyDeepFriedTwinkie(float dollar){
   char input;
   float total = 0;
   while(total <= 3.50){
      
       cout<<"Please insert coins:"<<endl;
       cout<<"n - Nickel"<<endl;
       cout<<"d - Dime"<<endl;
       cout<<"q - Quarter"<<endl;
       cout<<"D - Dollar"<<endl;
       cout<<"A fried TWINKIE costs $3.50. You have inserted $"<<fixed <<setprecision(2)<<total<<endl;
       cout<<"Next coin: ";
       cin>>input;
      
       if(input == 'n')
           total = total + 0.05;
       else if(input=='d')
           total = total + 0.10;
       else if(input == 'q')
           total = total + 0.25;
       else if(input =='D')
           total = total + 1;
       cin.ignore();
       }
       cout<<"Enjoy your deep-fried TWINKIE. Your change is $"<<fixed <<setprecision(2)<<total<<endl;
       return total - 3.50;
   }
  
int main(){
  
   char c = 'y';
   float dollar = 0.0;
   cout<<"WELCOME TO TWINKIE VENDING MACHINE"<<endl;
   cout<<"TWINKIES are $3.50 each."<<endl;
   //cin.ignore();
   while(c=='y' || c == 'Y'){
       dollar = buyDeepFriedTwinkie(dollar);
       cout<<"Would you like to purchase another?: "<<endl;
       cin>>c;
       }
   }


/*

Output:

WELCOME TO TWINKIE VENDING MACHINE
TWINKIES are $3.50 each.
Please insert coins:
n - Nickel
d - Dime
q - Quarter
D - Dollar
A fried TWINKIE costs $3.50. You have inserted $0.00
Next coin: n
Please insert coins:
n - Nickel
d - Dime
q - Quarter
D - Dollar
A fried TWINKIE costs $3.50. You have inserted $0.05
Next coin: q
Please insert coins:
n - Nickel
d - Dime
q - Quarter
D - Dollar
A fried TWINKIE costs $3.50. You have inserted $0.30
Next coin: D
Please insert coins:
n - Nickel
d - Dime
q - Quarter
D - Dollar
A fried TWINKIE costs $3.50. You have inserted $1.30
Next coin: D
Please insert coins:
n - Nickel
d - Dime
q - Quarter
D - Dollar
A fried TWINKIE costs $3.50. You have inserted $2.30
Next coin: q
Please insert coins:
n - Nickel
d - Dime
q - Quarter
D - Dollar
A fried TWINKIE costs $3.50. You have inserted $2.55
Next coin: q
Please insert coins:
n - Nickel
d - Dime
q - Quarter
D - Dollar
A fried TWINKIE costs $3.50. You have inserted $2.80
Next coin: D
Enjoy your deep-fried TWINKIE. Your change is $3.80
Would you like to purchase another?:
n

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote