Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Program Please help me fix my program to look better * Needs spacing *A message when the user entered an invalid choice (please add

C++ Program

Please help me fix my program to look better

* Needs spacing *A message when the user entered an invalid choice (please add message, ex "Invalid Choice") and the program will just show the options again *A choice when the user wants to exit the program (please add message, ex. "Thank you. Good bye!") and this will stop the program

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].price<=currentAmount&&softDrink[itemChoice].qnt>0){ //print the dispensed item cout<currentAmount){ //if amount is insufficient to buy item then give option to add money cout<<"Insufficient Amount : Rs "<>c; if(c=='Y'){ TakeAmount(); Dispense(); } }else if(softDrink[itemChoice].qnt==0){ //if the item is not available print message cout<<"Item not available"<0){ cout<currentAmount){ cout<<"Insufficient Amount : Rs "<>c; if(c=='Y'){ TakeAmount(); Dispense(); } }else if(hotDrink[itemChoice].qnt==0){ cout<<"Item not available"<0){ cout<currentAmount){ cout<<"Insufficient Amount : Rs "<>c; if(c=='Y'){ TakeAmount(); Dispense(); } }else if(snacks[itemChoice].qnt==0){ cout<<"Item not available"<>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<<"Would you also like to buy "<>c; if(c='Y'){ typeChoice=type; itemChoice=itm; Dispense(); } }else if(typeChoice==3){ int type=snacks[itemChoice].stype; int itm=snacks[itemChoice].sitem; cout<<"Would you also like to buy "<>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<<"Enter amount : "; cin>>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<<"You have recieved a change of Rs "<                        

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions