Chapter 2 – Q #4: Restaurant Bill – Tony Gaddis – Starting Out With C++

Chapter 2 – Q #4: Restaurant Bill – Tony Gaddis – Starting Out With C++

Restaurant Bill


Problem:- 


Write a program that computes the tax and tip on a restaurant bill for a patron with a $44.50 meal charge.
The tax should be 6.75 percent of the meal cost. The tip should be 15 percent 
of the total after adding the tax. Display the meal cost, tax amount, tip amount, and total bill on the screen.



Solution:-

#include <iostream>

using namespace std;

int main()

{

      const double meal = 44.50;

      double tax = (6.75 / 100.0) * meal;

      double tip = ((15 / 100.0) * meal) + tax;

 

      double total_bill = meal + tax + tip;

 

      cout << "Meal Cost   is    $" << meal << endl;

      cout << "Tax Ammount is    $" << tax << endl;

      cout << "Tip Ammount is    $" << tip << endl;

      cout << "Total Bill  is    $" << total_bill;

 

      return 0;

}

Here is the solution of this Question.


Explanation of Solution:-

  1. We declare a constant and initialize with meal price.
  2. Declare a tax variable and calculate tax value.
  3. Declare a tip variable and calculate value and also add tax value.
  4. Declare a total bill variable and add tax, tip and meal amount.
  5. Display output of meal, tax, tip and total bill amounts.
  6. Return 0 to the main function.

I also attach the cpp file of this solution. 


Thanks!



Post a Comment

0 Comments