fork(2) download
  1. //Xinnuo Wang CS1A Chapter 2, P. 81, #4
  2. //
  3. /*******************************************************************************
  4. *
  5. * COMPUTE Restaurant Bill
  6. * ______________________________________________________________________________
  7. * This program computes the tax and tip on a restaurant bill for a patron with
  8. * a $44.50 meal charge. The tax should be 6.75 percent of the meal cost. The tip
  9. * should be 15 percent of the total after adding the tax. Display the meal cost,
  10. * tax amount, tip amount, and total bill on the screen.
  11. *
  12. * Computation is based on the formula:
  13. * Tax = Meal charge x percentage on tax
  14. * Tip = Meal charge x percentage on tip
  15. * Bill = Meal charge + Tax + Tip
  16. * ______________________________________________________________________________
  17. * INPUT
  18. * mealCharge : Charge for food
  19. * percentageOnTax : The percentage of tax in meal charge
  20. * percentageOnTip : The percentage of tip in meal charge
  21. * OUTPUT
  22. * tax : Charge for tax
  23. * tip : Charge for tip
  24. * bill : The total cost on this meal
  25. *
  26. *******************************************************************************/
  27. #include <iostream>
  28. using namespace std;
  29.  
  30. int main()
  31. {
  32. float mealCharge; //INPUT - Charge for food
  33. float percentageOnTax; //INPUT - The percentage of tax in meal charge
  34. float percentageOnTip; //INPUT - The percentage of tip in meal charge
  35. float tax; //OUTPUT - Charge for tax
  36. float tip; //OUTPUT - Charge for tip
  37. float bill; //OUTPUT - The total cost on this meal
  38. //
  39. // Initialize Program Variables
  40. mealCharge = 44.50;
  41. percentageOnTax = 0.0675;
  42. percentageOnTip = 0.15;
  43. //
  44. //Output Result
  45. cout << "The meal cost is: $"<< mealCharge << endl;
  46. //
  47. //Compute the tax
  48. tax = mealCharge * percentageOnTax;
  49. //
  50. //Output Result
  51. cout << "The amount of tax on this meal is : $" << tax <<endl;
  52. //
  53. //Compute the tip
  54. tip = mealCharge * percentageOnTip;
  55. //
  56. //Output Result
  57. cout << "The amount of tip on this meal is : $" << tip <<endl;
  58. //
  59. //Compute the total bill
  60. bill = mealCharge + tax + tip;
  61. //
  62. //Output Result
  63. cout << "The total bill is" << bill << endl;
  64. return 0;
  65. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
The meal cost is: $44.5
The amount of tax on this meal is : $3.00375
The amount of tip on this meal is : $6.675
The total bill is54.1787