Question

In C++, using: juiceMachine.h, juiceMachineImp.cpp, main.pp as your file names The method sellProduct of the Juice...

In C++,

using: juiceMachine.h, juiceMachineImp.cpp, main.pp as your file names

The method sellProduct of the Juice Machine programming example gives the user only two chances to enter enough money to buy the product. Rewrite the definition of the method sellProduct so that it keeps prompting the user to enter more money as long as the user has not entered enough money to buy the product. Also, write a program to test your method.

Your program should produce the following output:

 *** Welcome to Shelly's Juice Shop ***                               
To select an item, enter                                             
1 for orange juice (50 cents)                                        
2 for apple juice (65 cents)                                         
3 for mango juice (80 cents)                                         
4 for strawberry banana juice (85 cents)                             
9 to exit                                                            
3                                                                    
Please deposit 80 cents                                              
40                                                                   
Please deposit another 40 cents.                                     
40                                                                   
Collect your item at the bottom and enjoy.                           
*** Welcome to Shelly's Juice Shop ***                               
To select an item, enter                                             
1 for orange juice (50 cents)                                        
2 for apple juice (65 cents)                                         
3 for mango juice (80 cents)                                         
4 for strawberry banana juice (85 cents)                             
9 to exit                                                            
9 
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code;

#include<iostream>
using namespace std;
//Redefined function
void sellProduct()
{
   int i,m,extram,choice;
   do{
       cout<<" *** Welcome to Shelly's Juice Shop ***\nTo select an item, enter\n1 for orange juice (50 cents)\n2 for apple juice (65 cents)\n3 for mango juice (80 cents)\n4 for strawberry banana juice (85 cents)\n9 to exit\n";
       cin>>choice;
       if(choice==1)
       {
           cout<<"Please deposit 50 cents:\n";
           cin>>m;
           while(m!=50&&m<50)
           {
               cout<<"Please deposit another "<<50-m<<" cents:";
               cin>>extram;
               m=m+extram;
           }
           cout<<"Collect your item at the bottom and enjoy:\n";
       }
       else if(choice==2)
       {
           cout<<"Please deposit 65 cents:\n";
           cin>>m;
           while(m!=65&&m<65)
           {
               cout<<"Please deposit another "<<65-m<<" cents:";
               cin>>extram;
               m=m+extram;
           }
           cout<<"Collect your item at the bottom and enjoy\n";
       }
       else if(choice==3)
       {
           cout<<"Please deposit 80 cents:\n";
           cin>>m;
           while(m!=80&&m<80)
           {
               cout<<"Please deposit another "<<80-m<<" cents:";
               cin>>extram;
               m=m+extram;
           }
           cout<<"Collect your item at the bottom and enjoy\n";
       }
       else if(choice==4)
       {
           cout<<"Please deposit 85 cents:\n";
           cin>>m;
           while(m!=85&&m<85)
           {
               cout<<"Please deposit another "<<85-m<<" cents:";
               cin>>extram;
               m=m+extram;
           }
           cout<<"Collect your item at the bottom and enjoy\n";
       }
      
   }while(choice!=9);
}
//Driver program
int main()
{
   sellProduct();
   return 0;
}

Output:

Bro, please comment if want any modifications or if you've any doubt...

Add a comment
Know the answer?
Add Answer to:
In C++, using: juiceMachine.h, juiceMachineImp.cpp, main.pp as your file names The method sellProduct of the Juice...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • COP 2220 Into programming in C(Answer in C, not C++). The question is: Please write the...

    COP 2220 Into programming in C(Answer in C, not C++). The question is: Please write the algorithm for a AppStore programming assignment. The details of the assignment, a sample algorithm, and its outline, are located below. Make the algorithm at least half a page, easy to read, and to understand, how it works. I just want the algorithm, not the programming code, I have that. I only need the ALGORITHM. Thanks for helping me out, I apprieciate it, have a...

  • C++ HW Question Your program will simulate a simple change maker for a vending machine. It...

    C++ HW Question Your program will simulate a simple change maker for a vending machine. It will start with a stock of coins and dollars. It will then repeatedly request the price for an item to be purchased or to quit. If given a price, it will accept nickels, dimes, quarters, one-dollar and five-dollar bills—deposited one at a time—in payment. When the user has deposited enough to cover the cost of the item, the program will calculate the coins to...

  • answer in c++ code. use comments when writing the code to know what's your thinking. there is three pictures with information Write a C++ console program that defines and utilizes a cl...

    answer in c++ code. use comments when writing the code to know what's your thinking. there is three pictures with information Write a C++ console program that defines and utilizes a class named ATM. This program will demonstrate a composition relationship among classes because an ATM can contain many Accounts. You will need to reuse/modify the Account class you created in Assignment 10. The default constructor for the ATM class should initialize a private vector of 10 accounts, each with...

  • Question 3.1 Draw the class diagram for the ATM program in Question 2.1. Please find attached...

    Question 3.1 Draw the class diagram for the ATM program in Question 2.1. Please find attached the scenario in the photos. this is for programming logic and design Scenario A local bank intends to install a new automated teller machine (ATM) to allow users (i.e., bank customers) to perform basic financial transactions (see below figure). Each user can have only one account at the bank. ATM users should be able to do the following; View their account balance. Withdraw cash...

  • I tried to add exception handling to my program so that when the user puts in...

    I tried to add exception handling to my program so that when the user puts in an amount of change that is not the integer data type, the code will catch it and tell them to try again, but my try/catch isnt working. I'm not sure how to fix this problem. JAVA code pls package Chapter9; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class GUIlab extends JFrame implements ActionListener {    private static final int WIDTH = 300;    private...

  • InventoryManagement

    Problem:A small electronics company has hired you to write an application to manage their inventory. The company requested a role-based access control (RBAC) to increase the security around using the new application. The company also requested that the application menu must be flexible enough to allow adding new menu items to the menu with minimal changes. This includes re-ordering the menu items and making changes to the description of a menu item without having to change the code.Security:The company has...

  • using java Program: Please read the complete prompt before going into coding. Write a program that...

    using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...

  • using C geany. Please Dr. exercise # 1 and 2 During the lab: PART I: PROGRAMMING...

    using C geany. Please Dr. exercise # 1 and 2 During the lab: PART I: PROGRAMMING EXERCISES a. Using Geany, write a C program that prompts and asks the user for two assignment marks (al and a2) and two test marks (ti and t2). All four variables are integer variables and are in % (out of 100). You program should display the four marks properly lalebed to check if the input has been successful. b. Next, calculate and display the...

  • Description This project is an enhancement of your previous project using OOP concepts. You'lI de...

    Please I need help a sample code is provided below of the output Description This project is an enhancement of your previous project using OOP concepts. You'lI define class and instantiate objects instead of using struct to implement your design Write a menu-driven program that provides the following options 1. Show All 2. Spend 3. Search expenses containing this string 4. Search expenses with greater than or equal to this amount 5. Exit It allows the user to select a...

  • 1) The image shows a completed schedule C using the cash method. Complete schedule C using...

    1) The image shows a completed schedule C using the cash method. Complete schedule C using the ACCRUAL method. 2) Are there any differences between the 2018 and 2019 forms? SCHEDULE C (Form 1040) Profit or Loss From Business (Sole Proprietorship) •Go to www.irs.gov/Schedulec for instructions and the latest information. OMB No. 1545-0074 2018 Department of the Treasury Internal Revenue Service (99) Name of proprietor RICK GRIME Attachment Attach to Form 1040, 1040NR, or 1041; partnerships generally must file Form...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT