fork download
  1. //Devin Scheu CS1A Chapter 2, P. 81, #4
  2. //
  3. /**************************************************************
  4. *
  5. * CALCULATE RESTAURANT BILL
  6. * ____________________________________________________________
  7. * This program calculates the restaurantBill given a
  8. * totalBill, a taxPercent and a tipPercent.
  9. *
  10. * Computation is based on the formulas:
  11. * billTaxAmount = restaurantBill * (taxPercent / 100);
  12. * billTipAmount = (restaurantBill + billTaxAmount) * (tipPercent / 100);
  13. * restaurantBill = totalBill + billTaxAmount + billTipAmount
  14. * ____________________________________________________________
  15. * INPUT
  16. * restaurantBill : Total cost of bill in dollars (as a double EX: 23.76)
  17. * taxPercent : Percentage of sales tax (as a double EX: 4.7)
  18. * tipPercent : Percentage bill to be tipped (as a double EX: 2.8)
  19. *
  20. * PROCESSING
  21. * billTaxAmount : The amount taxed (in dollars EX: $4.57)
  22. * billTipAmount : The amount tipped (in dollars EX: $4.57)
  23. *
  24. * OUTPUT
  25. * billTotal : The restuarant bills total amount (in dollars EX: $4.57)
  26. *
  27. **************************************************************/
  28.  
  29. #include <iostream>
  30. #include <iomanip>
  31.  
  32. using namespace std;
  33.  
  34. int main () {
  35.  
  36. //Variable Declarations
  37. double restaurantBill; //INPUT - Total cost of bill in dollars (as a double EX: 23.76)
  38. double taxPercent; //INPUT - Percentage of sales tax (as a double EX: 4.7)
  39. double tipPercent; //INPUT - Percentage bill to be tipped (as a double EX: 2.8)
  40. double billTaxAmount; //PROCESSING - The amount taxed (in dollars EX: $4.57)
  41. double billTipAmount; //PROCESSING - The amount tipped (in dollars EX: $4.57)
  42. double billTotal; //OUTPUT - The restuarant bills total amount (in dollars EX: $4.57
  43.  
  44. //Variable Initialization
  45. restaurantBill = 44.50;
  46. taxPercent = 6.75;
  47. tipPercent = 1.5;
  48.  
  49. //Calculate Amount For Tax and Tip
  50. billTaxAmount = restaurantBill * (taxPercent / 100);
  51. billTipAmount = (restaurantBill + billTaxAmount) * (tipPercent / 100);
  52.  
  53. //Caluclate Restaurant Bill
  54. billTotal = billTaxAmount + billTipAmount + restaurantBill;
  55.  
  56. //Output Result
  57. cout << fixed << setprecision(2) << "The total bill is: $" << billTotal << endl;
  58.  
  59. } //end of main()
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
The total bill is: $48.22