Problem A: Making Decisions You and two friends goes out to a restaurant for din
ID: 3885582 • Letter: P
Question
Problem A: Making Decisions
You and two friends goes out to a restaurant for diner, at the conclusion of the meal you all decided to evenly split the bill. We wrote a program that would compute the tax and tip of the restaurant bill, and also determined how much each person would have to put towards tip and the total bill.
Extend your program to determine the cost-savings each person will have by splitting the bill and only display a person’s cost-savings if they have a cost-savings.
Program Requirements:
The program should:
•Prompt the user for each person’s meal price (double)
•The tax should be 6.75 percent of the bill
•The tip should be 20 percent of the bill
•Use output manipulators (i.e. setprecision(2, fixed) to format the output as seen in output sample
•Use string objects instead of string literals to store the labels for the outputs to be displayed (i.e. taxLabel = ”Tax:”;)
Sample OUTPUT:
Enter the meal price for the first guest: $45.00
Enter the meal price for the second guest: $50.00
Enter the meal price for the third guest: $100.00
Tax: $13.16
Tip: $41.63
Total Bill: $249.79
Tip Per Person: $13.88
Total Per Person: $83.26
The 3rd guess saved: $16.74
Explanation / Answer
#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
double mealPriceFirstGuest;
double mealPriceSecondGuest;
double mealPriceThirdGuest;
double Tax;
double Tip;
double Total;
cout<<"Enter the meal price for the first guest: $";
cin>>mealPriceFirstGuest;
cout<<endl;
cout<<"Enter the meal price for the second guest: $";
cin>>mealPriceSecondGuest;
cout<<endl;
cout<<"Enter the meal price for the third guest: $";
cin>>mealPriceThirdGuest;
cout<<endl;
Tax=(6.75*(mealPriceFirstGuest+mealPriceSecondGuest+mealPriceThirdGuest)/100);
cout<<"Tax: $"<<setprecision(2)<<fixed<<Tax<<endl;
Tip=(20*(mealPriceFirstGuest+mealPriceSecondGuest+mealPriceThirdGuest+Tax)/100);
cout<<"Tip: $"<<setprecision(2)<<fixed<<Tip<<endl;
Total=mealPriceFirstGuest+mealPriceSecondGuest+mealPriceThirdGuest+Tip +Tax;
cout<<"Total Bill: $"<<setprecision(2)<<fixed<<Total<<endl;
cout<<"Tip Per Person: $"<<setprecision(2)<<fixed<<Tip/3<<endl;
double perPersonCost=Total/3;
cout<<"Total Per Person: $"<<setprecision(2)<<fixed<<perPersonCost<<endl;
double PriceFirstGuestTax=(6.75*mealPriceFirstGuest)/100;
double PriceFirstGuestTip =20*(PriceFirstGuestTax+mealPriceFirstGuest)/100;
double PriceFirstGuest=mealPriceFirstGuest+PriceFirstGuestTax+PriceFirstGuestTip;
if((PriceFirstGuest -perPersonCost)>0)
{
cout<<"The 1st guess saved: $"<<(PriceFirstGuest -perPersonCost);
}
double PriceSecondGuestTax=(6.75*mealPriceSecondGuest)/100;
double PriceSecondGuestTip =20*(PriceSecondGuestTax+mealPriceSecondGuest)/100;
double PriceSecondGuest=mealPriceSecondGuest+PriceSecondGuestTax+PriceSecondGuestTip;
if((PriceSecondGuest -perPersonCost)>0)
{
cout<<"The 2nd guess saved: $"<<(PriceSecondGuest -perPersonCost);
}
double PriceThirdGuestTax=(6.75*mealPriceThirdGuest)/100;
double PriceThirdGuestTip =20*(PriceThirdGuestTax+mealPriceThirdGuest)/100;
double PriceThirdGuest=mealPriceThirdGuest+PriceThirdGuestTax+PriceThirdGuestTip;
if((PriceThirdGuest -perPersonCost)>0)
{
cout<<"The 3rd guess saved: $"<<(PriceThirdGuest -perPersonCost);
}
return 0;
}
OUTPUT:
Enter the meal price for the first guest: $45.00
Enter the meal price for the second guest: $50.00
Enter the meal price for the third guest: $100.00
Tax: $13.16
Tip: $41.63
Total Bill: $249.79
Tip Per Person: $13.88
Total Per Person: $83.27
The 3rd guess saved: $44.83
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.