fork download
  1. //Julio Ramirez CSC5 Chapter 2, P. 81, #4
  2.  
  3. /*******************************************************************************
  4.  * Compute Restrant Bill
  5.  * _____________________________________________________________________________
  6.  * This program computes the tax and tip (in any appliable currency) based on
  7.  * the meal charge,
  8.  * tax percentage and tip percentage.
  9.  *
  10.  * Computation is based on the Formula:
  11.  * Tax Amount = Meal Charge * Tax Percentage
  12.  * Tip Amount = (Meal Charge + Tax) * Tip Percentage
  13.  * Total Bill = Meal Charge + Tax Amount + Tip Amount
  14.  * _____________________________________________________________________________
  15.  * INPUT
  16.  * meal : Meal charge
  17.  * taxPer : Tax percentage
  18.  * tipPer : Tip percentage
  19.  *
  20.  * OUTPUT
  21.  * tax : Tax amount
  22.  * tip : Tip amount
  23.  * total : Total bill
  24.  *
  25.  ******************************************************************************/
  26. #include <iostream>
  27. #include <iomanip>
  28. using namespace std;
  29.  
  30. int main()
  31. {
  32. float meal; //Input - Meal charge
  33. float taxPer; //Input - Tax Percentage
  34. float tipPer; //Input - Tip Percentage
  35. float tax; //Output - Tax amount
  36. float tip; //Output - Tip amount
  37. float total; //Output - Total
  38.  
  39. // Initialize Program Variables
  40. meal = 44.50;
  41. taxPer = 0.0675;
  42. tipPer = .15;
  43.  
  44. // Compute Tax
  45. tax = meal * taxPer;
  46.  
  47. // Compute Tip
  48. tip = (meal + tax) * tipPer;
  49.  
  50. // Compute Total
  51. total = meal + tip + tax;
  52.  
  53. // Output Results
  54. cout << "Sub Total : $" << setprecision(4) << showpoint << meal;
  55. cout << "\nTax" << setw(10) << ": $" << setprecision(3) << showpoint << tax;
  56. cout << "\nTip" << setw(10) << ": $" << setprecision(3) << showpoint << tip;
  57. cout << "\nTotal" << setw(8) << ": $" << setprecision(4) << showpoint << total;
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
Sub Total : $44.50
Tax       : $3.00
Tip       : $7.13
Total     : $54.63