// Need help revising and/or adding functions to print order summary,
// including the products, the quantities, tax and the total price for each product.
// Calculate tax and print the total price for the order.
// Please add comments to suggested revisions and/or the addition of
// functions, thanks
using namespace std;
int main()
{
char response;
double price,subtl;
int code,quantity;
cout<<"Welcome to the Creative Edge!\n";
cout<<"Specializing in Homemade, Vintage and Restored Items \n";
cout<<"Would you like to choose a product and enter the quantity (Y/N)\n";
cin>>response;
double total = 0; //allows you to use += to calculate produce subtotal since no tax.
//Will also reset total to 0 when you want to serve a new customer.
do
{
cout<<"\nEnter Code:";
cin>>code;
switch(code)//the () tells what variable to use and the case are what value will cause that to occur.
{
case 101:
cout<<"Handmade Graphic Tshirts 22.00"<<endl;
cout<<"Enter Quantity: ";
cin>>quantity;
if(quantity<=0)
{cout<<"Invalid Quantity"<<endl;
cin>>quantity;}
price=22.00;
subtl=(quantity*price);
cout<<"Subtotal $\n"<<subtl<<endl;
break; //breaks from case to continue in function
case 606:
cout<<"Restored Metal Containers 48.00"<<endl;
cout<<"Enter Quantity:";
cin>>quantity;
if(quantity<=0)
{cout<<"Invalid Quantity"<<endl;
cin>>quantity;}
price=48.00;
subtl=(quantity*price);
cout<<"Subtotal $\n"<<subtl<<endl;
break;
case 0://Sentinal value that gives subtotal (because no tax) then ends your function.
cout<<"Subtotal: \n"<<total<<endl;
break;
default:
cout<<"Invalid Code!"<<endl;
break;
}
total+=subtl; //will add all the produce values up. is read as total=total+subt
}
while (code!=0);//checks if code = 0 at the end of function wont end till it is.
}
cout<<"Would you like to continue shopping?(Y/N)";
cin>>response;
}
You have a lot of repeating code. Code that stays the same should not be in your case statements; it should only be typed out once, within your while loop. Use function calls for data that varies.