fork download
  1. // Torrez, Elaine CS1A Chapter 2 P. 81, #4
  2.  
  3. /******************************************************************************************
  4.  *
  5.  * CALCULATE RESTAURANT BILL TOTAL
  6.  *
  7.  * --------------------------------------------------------------------------------
  8.  * This program calculates the tax and tip from the total cost of a restaurant bill.
  9.  * It then displays the meal cost, tax amount, tip amount, and total.
  10.  * --------------------------------------------------------------------------------
  11.  *
  12.  * INPUT
  13.  * mealCost : cost of the meal before tax and tip
  14.  * taxRate : 6.75%
  15.  * tipRate : 15%
  16.  *
  17.  * OUTPUT
  18.  * mealTax : 6.75% of the meal cost
  19.  * mealTip : 15% of the meal cost + tax
  20.  * total : meal cost + tax + tip
  21.  *
  22.  *******************************************************************************************/
  23.  
  24. #include <iostream>
  25. #include <iomanip> // Included for fixed and setprecision
  26. using namespace std;
  27.  
  28. int main()
  29. {
  30. double mealCost; // Cost of the meal
  31. double mealTax; // Tax on the meal
  32. double mealTip; // Tip on meal + tax
  33. double total; // Total cost including tax and tip
  34.  
  35. mealCost = 44.50; // INPUT meal cost
  36. mealTax = mealCost * 0.0675; // Compute tax
  37. mealTip = (mealCost + mealTax) * 0.15; // Compute tip
  38. total = mealCost + mealTax + mealTip; // Compute total
  39.  
  40. cout << fixed << setprecision(2);
  41.  
  42. // OUTPUT
  43. cout << "Meal Cost : $" << mealCost << endl;
  44. cout << "Tax (6.75%): $" << mealTax << endl;
  45. cout << "Tip (15%) : $" << mealTip << endl;
  46. cout << "Total Bill : $" << total << endl;
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
Meal Cost : $44.50
Tax (6.75%): $3.00
Tip (15%)  : $7.13
Total Bill : $54.63