In: Computer Science
Using C++ write a program to calculate the amount a customer should pay in a self checkout counter for his purchases in a bagel shop. The products sold are everything bagels, garlic bagels, blueberry bagels, cream cheese, and coffee. Using "doWhile loops" write the program to display the menu of the Bagel shop. Make the user buy multiple items of different choices. Finally display the total amount for the purchases. Below is my current code to work with. Please add comments to help me understand the code.
//This program implements bagel shop PoS #include <iostream> #include <iomanip> using namespace std; const float EVERY_BAGEL_COST = 1.99; const float BLUE_BAGEL_COST = 1.99; const float GARLIC_BAGEL_COST = 1.99; const float CREAM_CHEESE_COST = 2.99; const float COFFEE_COST = 3.99; int main() { char choice; int cnt; double total_charges = 0.0; double charges_every = 0.0; double charges_blueberry = 0.0; double charges_garlic = 0.0; double charges_cream = 0.0; double charges_coffee = 0.0; cout << fixed << showpoint << setprecision(2); cout << "Please pick one item from the menu:" << endl << endl; cout << "Enter A for Everything Bagel" << endl; cout << "Enter B for Blueberry Bagel" << endl; cout << "Enter C for Garlic Bagel" << endl; cout << "Enter D for Cream Cheese" << endl; cout << "Enter E for coffee" << endl; cout << "Enter F for quit" << endl << endl; do { // get the choice from A to F cout << "\nEnter your choice of food: "; cin >> choice; switch (choice) { case 'A': cout << "Enter number of items : "; cin >> cnt; charges_every += (EVERY_BAGEL_COST * cnt); break; case 'B': cout << "Enter number of items : "; cin >> cnt; charges_blueberry += (BLUE_BAGEL_COST * cnt); break; case 'C': cout << "Enter number of items : "; cin >> cnt; charges_garlic += (GARLIC_BAGEL_COST * cnt); break; case 'D': cout << "Enter number of items : "; cin >> cnt; charges_cream += (CREAM_CHEESE_COST * cnt); break; case 'E': cout << "Enter number of items : "; cin >> cnt; charges_coffee += (COFFEE_COST * cnt); break; case 'F': break; default: cout << "Enter a choice between A to F" << endl; } } while (choice != 'F'); total_charges = charges_every + charges_coffee + charges_cream + charges_blueberry + charges_garlic; cout << "\nEverything Bagel : $" << charges_every << endl; cout << "\nBlueberry Bagel : $" << charges_blueberry << endl; cout << "\nGarlic Bagel : $" << charges_garlic << endl; cout << "\nCream Cheese : $" << charges_cream << endl; cout << "\ncoffee : $" << charges_coffee << endl; cout << "\nTotal charges are: $" << total_charges << endl; cout << endl; return 0; }
//################# PGM START #################################
//This program implements bagel shop PoS
#include <iostream>
#include <iomanip>
using namespace std;
const float EVERY_BAGEL_COST = 1.99;
const float BLUE_BAGEL_COST = 1.99;
const float GARLIC_BAGEL_COST = 1.99;
const float CREAM_CHEESE_COST = 2.99;
const float COFFEE_COST = 3.99;
int main()
{
char choice;
int cnt;
double total_charges = 0.0;
double charges_every = 0.0;
double charges_blueberry = 0.0;
double charges_garlic = 0.0;
double charges_cream = 0.0;
double charges_coffee = 0.0;
cout << fixed << showpoint <<
setprecision(2);
//re[eat untill user want to exit (ie choice
F)
do
{
//menu items for user
cout << "Please pick one item
from the menu:" << endl;
cout<<"______________________________________"<<
endl;
cout << "Enter A for
Everything Bagel" << endl;
cout << "Enter B for
Blueberry Bagel" << endl;
cout << "Enter C for Garlic
Bagel" << endl;
cout << "Enter D for Cream
Cheese" << endl;
cout << "Enter E for coffee"
<< endl;
cout << "Enter F for quit"
<< endl<< endl;
// get the choice from A to
F
cout << "\nEnter your choice
of food: ";
cin >> choice;
cnt=0;
//if the choice is fom A to E , get
the number of items from user
if(choice=='A' || choice=='B' ||
choice=='C' || choice=='D' || choice=='E'){
cout <<
"Enter number of items : ";
cin >>
cnt;
cin.ignore();
}
//for A to E calculate the
cost
switch (choice) {
case
'A': charges_every += (EVERY_BAGEL_COST * cnt);
break;
case 'B':
charges_blueberry += (BLUE_BAGEL_COST * cnt);
break;
case 'C':
charges_garlic += (GARLIC_BAGEL_COST * cnt);
break;
case 'D':
charges_cream += (CREAM_CHEESE_COST * cnt);
break;
case 'E':
charges_coffee += (COFFEE_COST * cnt);
break;
case 'F':
break;
default:
cout << "Enter a choice between A to F" << endl;
}
cout<<endl;
} while (choice != 'F');
//find the total charge
total_charges = charges_every + charges_coffee
+charges_cream + charges_blueberry +charges_garlic;
//print the cost of each item and final
amount
cout << "\nEverything Bagel : $" <<
charges_every << endl;
cout << "\nBlueberry Bagel : $" <<
charges_blueberry << endl;
cout << "\nGarlic Bagel : $" <<
charges_garlic << endl;
cout << "\nCream Cheese : $" <<
charges_cream << endl;
cout << "\ncoffee : $" <<
charges_coffee << endl;
cout << "\nTotal charges are: $" <<
total_charges << endl;
cout << endl<<endl;
return 0;
}
//##################### PGM END #######################
OUTPUT
###########