Here is my homework assignment. I need to create a loop for the total price of f
ID: 3539140 • Letter: H
Question
Here is my homework assignment. I need to create a loop for the total price of frozen yogurt orders. The price of size small, medium and large are 2.19, 3.49, and 4.49 respectively.
______________________________________________________
Welcome to My Frozen Yogurt!
What size would you like?
Please enter small, medium, or large: small
Enter flavor 1: chocolate
Enter flavor 2: rocky road
Enter flavor 3: DONE
** Order 1: small choc-rock **
Would you like to add another order?
Please enter yes or no: yes
What size would you like?
Please enter small, medium, or large: large
Enter flavor 1: berry blast
Enter flavor 2: Hawaiian surprise
Enter flavor 3: paradise found
** Order 2: large berr-Hawa-para **
Would you like to add another order?
Please enter yes or no: no
Subtotal: $6.68
Tax (8.75%): $0.58
Total: $7.26
Press any key to continue...
__________________________________________________________
I wrote a do while loop to repeat the steps of orders if a customer wants to add another order. But I don't know how to write the code to add up the subtotal price of order 1, order 2, order 3 and so on. Please help me with these!
Explanation / Answer
#include <iostream>
#include <string>
#include <stdio.h>
#include <iomanip>
using namespace std;
int main()
{
//setting precision after decimal for cout
std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
std::cout.precision(2);
double subTotal = 0;
string choice;
int i=1;
cout<<"Welcome to My Frozen Yogurt!"<<endl;
do
{
string size;
cout<<" What size would you like? ";
cout<<"Please enter small, medium, or large: ";
cin>>size;
while(size!="small" && size!="medium" && size!="large")
{
cout<<"Please enter small, medium, or large: ";
cin>>size;
}
if(size=="small"||size=="medium")
{
cout<<" Enter flavor 1: chocolate"<<endl;
cout<<"Enter flavor 2: rocky road"<<endl;
cout<<"Enter flavor 3: DONE"<<endl;
cout<<"** Order "<<i<<": "<<size<<" choc-rock **"<<endl;
if(size=="small")
{
subTotal = subTotal + 2.19;
}
else
{
subTotal = subTotal + 3.49;
}
}
else
{
cout<<" Enter flavor 1: berry blast"<<endl;
cout<<"Enter flavor 2: Hawaiian surprise"<<endl;
cout<<"Enter flavor 3: paradise found"<<endl;
cout<<"** Order "<<i<<": large berr-Hawa-para **"<<endl;
subTotal = subTotal + 4.49;
}
i++;
cout<<" Would you like to add another order?"<<endl;
cout<<"Please enter yes or no: ";
cin>>choice;
while(choice != "yes" && choice!= "no")
{
cout<<"Please enter yes or no: ";
cin>>choice;
}
}while(choice=="yes");
double tax = 0.0875*subTotal;
cout<<" Subtotal: $"<<subTotal<<endl;
cout<<"Tax (8.75%): $"<<tax<<endl;
cout<<"Total: $"<<subTotal+tax<<endl;
cout<<" Press any key to continue...";
getchar();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.