fork download
  1. // Cameron Pham CS1A chapter 2, p. 81, #4
  2. //
  3. /******************************************************************************
  4.  *
  5.  * Displaying Meal Cost, Tax Amount, Tip Amount, and Total Bill for a Meal
  6.  *
  7.  * _____________________________________________________________________________
  8.  * This program computes and displays the tax and tip amount of a restaurant
  9.  * bill for a $44.50 meal charge based on the meal cost, tax percentage, and tip
  10.  * percentage after tax. It will also display the total bill.
  11.  *
  12.  * Computation is based on the formula:
  13.  * taxAmount = mealCost * taxPercent
  14.  * tipAmount = (mealCost + taxAmount) * tipPercent
  15.  * totalBill = taxAmount + tipAmount + mealCost
  16.  *
  17.  * _____________________________________________________________________________
  18.  * INPUT
  19.  * mealCost = initial charge of meal ($44.50)
  20.  * taxPercent = sales tax (6.75%)
  21.  * tipPercent = tip percent based on charge after tax (15%)
  22.  *
  23.  * OUTPUT
  24.  * taxAmount = charge of tax
  25.  * tipAmount = charge of tip after tax
  26.  * totalBill = computes total charge of meal
  27.  *
  28.  * ****************************************************************************/
  29. #include <iostream>
  30. using namespace std;
  31.  
  32. int main()
  33. {
  34. double mealCost; // INPUT - The initial charge of meal
  35. double taxPercent; // INPUT - The tax rate percentage
  36. double tipPercent; // INPUt - The tip percentage
  37. double taxAmount; // OUTPUT - The charge of tax
  38. double tipAmount; // OUTPUT - The charge of tip
  39. double totalBill; // OUTPUT - The total charge
  40.  
  41. // Initialize Program Variables
  42. mealCost = 44.50;
  43. taxPercent = 0.0675;
  44. tipPercent = 0.15;
  45.  
  46. // Computing Charges
  47. taxAmount = mealCost * taxPercent;
  48. tipAmount = (mealCost + taxAmount) * tipPercent;
  49. totalBill = taxAmount + tipAmount + mealCost;
  50.  
  51. // Final Output
  52. cout <<"Meal cost = $ " << mealCost << "0" << endl;
  53. cout <<"Tax amount = $ " << taxAmount << endl;
  54. cout << "Tip amount = $ " << tipAmount << endl;
  55. cout << "Total bill = $ " << totalBill << endl;
  56.  
  57. return 0;
  58. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Meal cost = $ 44.50
Tax amount = $ 3.00375
Tip amount = $ 7.12556
Total bill = $ 54.6293