Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

C++ PROGRAM I JUST NEED ADDITIONAL CODE ON MY PROGRAM Add the following: - Since it is console, the graphical representation should make use of

C++ PROGRAM

I JUST NEED ADDITIONAL CODE ON MY PROGRAM

Add the following: - Since it is console, the graphical representation should make use of text elements (fix the spacing on each output)

- Add another condition that if the user enter the wrong number, a message should appear "INVALID CHOICE"

- Add another condition to exit to the program, a message should appear "THANK YOU~"

SOURCE CODE

#include #include using namespace std; //struct item to store the attributes of each item struct item{ string name; double price; int qnt; int stype; int sitem; }; //Declarations for each methods void Dispense(); void Suggest(); string getItemName(int type,int itm); void TakeAmount(); void DisplaySoftDrinks(); void DisplayHotDrinks(); void DisplaySnacks(); void DisplayMenu(); //global arrays declarations to store different categories of items item softDrink[5]; item hotDrink[3]; item snacks[5]; int softDrinkLen=5; int hotDrinkLen=3; int snacksLen=5; //global variables declarations int typeChoice = -1; int itemChoice = -1; double paidAmount = 0; double returnAmount = 0; double currentAmount = 0; int more = 1; char c; int suggested = 0; //Dispense method checks the availability and sufficiency of amount to buy the item and then dispenses the item void Dispense(){ //check which type of item if(typeChoice==1){ //if price of item is less than current balance and if the item is available if(softDrink[itemChoice].price0){ //print the dispensed item coutcurrentAmount){ //if amount is insufficient to buy item then give option to add money cout>c; if(c=='Y'){ TakeAmount(); Dispense(); } }else if(softDrink[itemChoice].qnt==0){ //if the item is not available print message cout0){ coutcurrentAmount){ cout>c; if(c=='Y'){ TakeAmount(); Dispense(); } }else if(hotDrink[itemChoice].qnt==0){ cout0){ coutcurrentAmount){ cout>c; if(c=='Y'){ TakeAmount(); Dispense(); } }else if(snacks[itemChoice].qnt==0){ cout>c; //if customer wants to buy the suggested item then dispenses it if(c='Y'){ typeChoice=type; itemChoice=itm; Dispense(); } }else if(typeChoice==2){ int type=hotDrink[itemChoice].stype; int itm=hotDrink[itemChoice].sitem; cout>c; if(c='Y'){ typeChoice=type; itemChoice=itm; Dispense(); } }else if(typeChoice==3){ int type=snacks[itemChoice].stype; int itm=snacks[itemChoice].sitem; cout>c; if(c='Y'){ typeChoice=type; itemChoice=itm; Dispense(); } } } //getItemName method return the name of the item given its type and item code string getItemName(int type,int itm){ if(type==1){ return softDrink[itm].name; }else if(type==2){ return hotDrink[itm].name; }else if(type==3){ return snacks[itm].name; } } //TakeAmount method takes input from the user and adds the amount to the current amount void TakeAmount(){ cout>paidAmount; currentAmount+=paidAmount; cout>typeChoice; cout>itemChoice; cout>itemChoice; cout>itemChoice; cout>c; //if customer want to exit //returned amount is displayed with a thank you message // and the 'more' variable is updated so that the loop terminates if(c=='N'){ cout 

OUTPUT

image text in transcribed

X CS C:\Users\Acer\Desktop\CodeLab-1\Vending Machine\Debug\Vending Machine.exe Welcome! Please enter money : Enter amount : 500 Please enter choices for items you would like to buy : Enter 1 for Soft Drinks : 1. Cola Rs 20 (20 available) 2. Root Beer Rs 20 (20 available) 3. Lemon Lime Rs 20 (20 available) 4. Grape Soda Rs 20 (20 available) 5. Cream Soda Rs 20 (20 available) Enter 2 for Hot Drinks : 1. Coffee Rs 20 (20 available) 2. Tea Rs 20 (20 available) 3. Hot Chocolate Rs 20 (20 available) Enter 3 for Snacks : 1. Biscuit Rs 20 (20 available) 2. Chips Rs 20 (20 available) 3. Soya Sticks Rs 20 (20 available) 4. Cookies Rs 20 (20 available) 5. Chocolate Rs 20 (20 available) Enter your choice : 1 Which Soft Drink would you like to buy : 1. Cola Rs 20 (20 available) 2. Root Beer Rs 20 (20 available) 3. Lemon Lime Rs 20 (20 available) 4. Grape Soda Rs 20 (20 available) 5. Cream Soda Rs 20 (20 available) Enter your choice :2 Lemon Lime dispensed Remaining Amount : 480 Would you also like to buy Chips with your drink (Y/N): n Chips dispensed Remaining Amount : 460 would you like to buy anything else (Y/N): n Please enter choices for items you would like to buy : Enter 1 for Soft Drinks : 1. Cola Rs 20 (20 available) 2. Root Beer Rs 20 (20 available) 3. Lemon Lime Rs 20 (19 available)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions