Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program that computes the tax and tip on a restaurant bill. The prog

ID: 3747586 • Letter: W

Question

Write a C++ program that computes the tax and tip on a restaurant bill. The program should prompt the user to enter the cost of a meal. The tax is computed at 6.75% of the meal cost. Tip is calculated as a percentage of the meal cost inclusive of the tax. Your program should compute the tip at 15%, 20% and 25% and then output the total amount on the bill for the three different tip amounts. To format the output of your program you will need to use the <iomanip> (stands for I/O manipulation) library.

Observations

For formatting your output you will need to use the functions fixed and setprecision(), available in the <iomanip> library.

- Work on the output formatting part at the end, once you know your program is producing the correct results.

- Give some thought into choosing the right data types for your variables.

- Use named constants where appropriate.

- Document your code. Add comments describing your algorithm. Add comments describing the purpose of the variables you use.

Sample of what your program should looked like Input/Output

Please enter meal cost: 100

The total bill with a 15% tip is $122.76

The total bill with a 20% tip is $128.10

The total bill with a 25% tip is $133.44

Please enter meal cost : 200.00

The total bill with a 15% tip is $245.52

The total bill with a 20% tip is $256.20

The total bill with a 25% tip is $266.88

- Note, the prompt “Please enter meal cost:” is not part of the input. The prompt is something your program should display on the screen. Also note there is no end-of-line at the end of the prompt.

- Note the blank line between the prompt and the output lines.

- Note the $ signs before the total bill amounts

Explanation / Answer

For almost every line of code used a describing comment is added beside it, please look into it to understand it perfectly. If you still have any doubt feel free to comment on this answer.

************************************************************************************

// Example program
#include <iostream>
#include <iomanip>
using namespace std;       //so the we don't have to write 'std:: ' everytime we use 'cin' or 'cout', just declaring it as namespace
int main()
{
string name;
float cost;    //because meal cost can also be a floating value, ex $142.86
float costAfterTax; //to calculate the cost of meal just after adding taxes over meal cost
cout << "Please enter meal cost: "; //prompt for user to ask them to enter the meal cost, here asking user for input
cin >> cost; //getting user input in 'cost' variable
costAfterTax = cost + (0.0675 * cost); //calulating cost of meal after adding taxes at 6.75%
cout << fixed; //fixed from iomanip library will set the value after decimal point fixed to some given number
/*
    1. setprecision(2) sets value after decimal point fixed to exactly two positions
    2. we are calculating tip at variable rates on costAfterTax value so that we get the final cost of meal to be paid
*/
cout << "The total bill with a 15% tip is $" << setprecision(2) <<   costAfterTax + (0.15 * costAfterTax) << endl;
cout << "The total bill with a 20% tip is $" << setprecision(2) <<   costAfterTax + (0.20 * costAfterTax) << endl;
cout << "The total bill with a 25% tip is $" << setprecision(2) <<   costAfterTax + (0.25 * costAfterTax) << endl;
}


************************************************************************************8

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote