Question

Below is the C++ code for a very simple program that calculates the tax and tip...

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;  
}

Homework Answers

Answer #1
/* 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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Lab: RectClass (constructor) Code in C++ This program creates a Rectangle object, then displays the rectangle's...
Lab: RectClass (constructor) Code in C++ This program creates a Rectangle object, then displays the rectangle's length, width, and area Define an overloaded constructor and use it when creating the Rectangle object instead of using the setters. Change this program to calculate and display the rectangle's perimeter. Example: In feet, how wide is your house? 20 In feet, how long is your house? 25 The house is 20.00 feet wide. The house is 25.00 feet long. The house has 500.00...
Write a C++ program that processes orders for our company Widgets and More. Your program will...
Write a C++ program that processes orders for our company Widgets and More. Your program will read the product code and quantity for all the products in an order from a file, order.txt. You will be given a sample order.txt with the starter code. There are two items on each line of the file the first is a letter that represents the product and the second is an integer representing the number bought. Based on the product and quantity, you...
C ++ program that will read in prices and store them into a two-dimensional array //...
C ++ program that will read in prices and store them into a two-dimensional array // It will print those prices in a table form and the lowest price. // EXAMPLE // Input: // Please input the number of rows from 1 to 10 // 2 // Please input the number of columns from 1 to 10 // 3 // // Input price of item (0,0): 2 // Input price of item (0,1): 4 // Input price of item (0,2):...
Trace the C++ program below showing all output in the order that it is displayed. If...
Trace the C++ program below showing all output in the order that it is displayed. If anything happens that makes it impossible to accomplish an operation or the results of so doingare unpredictable, describe what happens and abort the program at that point. Assume the Queue class is fully defined in an appropriate header and implementation file. The effect of the functions (methods) is as follows - Constructor - creates an empty queue #include <iostream> #include using namespace std; #include...
tacks. Trace the C++ program below showing all output in the order that it is displayed....
tacks. Trace the C++ program below showing all output in the order that it is displayed. If anything happens that makes it impossible to accomplish an operation or the results of so doing are unpredictable, describe what happens and abort the program at that point. Assume the Stack class is fully defined in an appropriate header and implementation file. The effect of the functions (methods) is as follows: constructor - creates an empty stack empty - returns true if the...
How to stop the program from exiting after display detail. When there is food detail, it...
How to stop the program from exiting after display detail. When there is food detail, it will display and exit the program. What can i do to make it not exit the program and back to main menu. #include <iostream> #include <iomanip> #include<string.h> using namespace std; struct food{ int order_id; string food_code,flavor,customer_id; string address,name; int weight,unit_price,qty,contact_number; struct food *next; };    class Foodsystem{ food *head,*temp,*temp2,*end; static int id;    public: Foodsystem(){ head=NULL;end=NULL;} void Place_Order(); void View_food_details(); void Modify_food_details(); void Delete_food_details();...
Below is my C++ program. There is a function to add data, display it and search...
Below is my C++ program. There is a function to add data, display it and search the data. Just add two more functions to this porgram. One function to update the student data and second function to delete the data. Also, change the display function little bit. Right now, it shows all data entered. Make it so you have to put the uin number and it only displays the data of that specific student. #include <iostream> #include <string> using namespace...
/* Homework Lab 4 - Using manipulators to format output */ //***************************************************************** // Mortgage Payment Calculator...
/* Homework Lab 4 - Using manipulators to format output */ //***************************************************************** // Mortgage Payment Calculator program // This program determines the monthly payments on a mortgage given // the loan amount, the yearly interest, and the number of years. //***************************************************************** #include <iostream> // Access cout #include <cmath> // Access power function #include <iomanip> // Access manipulators using namespace std; const float LOAN_AMOUNT = 50000.00; // Amount of the loan const float YEARLY_INTEREST = 0.0524; // Yearly interest rate const...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include <cmath> using namespace std; int getWeight(); float deliveryCharge(int weight); void displayCharge(int weight); int main () {    displayCharge(getWeight());    return 0; }   int getWeight() {    int weight;    cout << "Enter package weight (oz): ";    cin >> weight;    return weight; } float deliveryCharge(int weight) {    if (weight > 16)    {        return (((weight - 16) / 4) *...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their relationship with arrays 2. To introduce the dereferencing operator 3. To introduce the concept of dynamic memory allocation A distinction must always be made between a memory location’s address and the data stored at that location. In this lab, we will look at addresses of variables and at special variables, called pointers, which hold these addresses. The address of a variable is given by...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT