Below is the C++ code for a very simple program that calculates the tax and tip amount for the bill at a restaurant then displays all the totals
the code compiles and runs fine but when it displays the values the decimal places are wrong I know you can use setprecision() to help fix this issue but i'm not sure how to implement it
or if there is a more effective way of doing it if someone could look at this help point me in the right direction
/* This program computes the tax and tip on a restaurant
bill
for a patron with a $88.67 meal charge. The tax should be 6.75
percent
of the meal cost. The tip should be 20 percent of the total
after adding the tax. Display the meal cost, tax amount, tip
amount
and total bill on the screen.
*/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double Bill = 88.75,
Tax =
.0675,
SalesTax, //Holds the
sales tax
Bill_Total, //Holds the bill total
after tax
Tip_percentage =
.2,
Tip_total, //Hold the tip total after taxes
Total; //Total of bill after
tip
SalesTax = Bill * Tax;
Bill_Total = Bill + SalesTax;
Tip_total = Bill_Total * Tip_percentage;
Total = Bill_Total + Tip_total;
//Display Totals
cout<<"The Bill total before taxes is $"
<< Bill << endl;
cout<<"The taxes for the meal is $" <<
SalesTax << endl;
cout<<"The Bill after taxes is $" <<
Bill_Total << endl;
cout<<"The Tip for the meal is $" <<
Tip_total << endl;
cout<<"The total after the Taxes and tip is $"
<< Total << endl;
return 0;
}
/* This program computes the tax and tip on a restaurant bill for a patron with a $88.67 meal charge. The tax should be 6.75 percent of the meal cost. The tip should be 20 percent of the total after adding the tax. Display the meal cost, tax amount, tip amount and total bill on the screen. */ #include <iostream> #include <iomanip> using namespace std; int main() { double Bill = 88.75, Tax = .0675, SalesTax, //Holds the sales tax Bill_Total, //Holds the bill total after tax Tip_percentage = .2, Tip_total, //Hold the tip total after taxes Total; //Total of bill after tip SalesTax = Bill * Tax; Bill_Total = Bill + SalesTax; Tip_total = Bill_Total * Tip_percentage; Total = Bill_Total + Tip_total; cout << setprecision(2) << fixed; cout << "The Bill total before taxes is $" << Bill << endl; cout << "The taxes for the meal is $" << SalesTax << endl; cout << "The Bill after taxes is $" << Bill_Total << endl; cout << "The Tip for the meal is $" << Tip_total << endl; cout << "The total after the Taxes and tip is $" << Total << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.