fork download
  1. // Jeremy Huang CS1A Chapter 2, Pp. 81, #4
  2.  
  3. /*****************************************************************************
  4.  * COMPUTE TOTAL RESTAURANT BILL
  5.  * ____________________________________________________________________________
  6.  * This program calculates the total cost of a restaurant bill by adding tax
  7.  * and tip to the original meal charge. The user inputs the tax and tip as a
  8.  * percent in which the program takes those values to compute and add to the
  9.  * original meal charge. The program then outputs the original meal charge,
  10.  * tax, tip, and the total bill.
  11.  * ___________________________________________________________________________
  12.  * INPUT
  13.  * mealCost : cost of the original meal
  14.  * taxRate : the tax rate
  15.  * tipRate : the tip rate
  16.  *
  17.  * OUTPUT
  18.  * mealCost : cost of the original meal
  19.  * taxAmount : the tax amount
  20.  * tipAmount : the tip amount
  21.  * totalBill : the total bill (meal+tax+tip)
  22.  *
  23.  * **************************************************************************/
  24.  
  25. #include <iostream>
  26. using namespace std;
  27.  
  28. int main() {
  29. //Declaring variables
  30. float mealCost = 44.50;
  31. float taxRate = 0.0675;
  32. float tipRate = 0.15;
  33.  
  34. //Computing formulas
  35. float taxAmount = mealCost*taxRate;
  36. float tipAmount = mealCost*tipRate;
  37. float totalBill = mealCost+taxAmount+tipAmount;
  38.  
  39. //Output
  40. cout<<"Meal Cost: $"<<mealCost<<endl;
  41. cout<<"Tax Amount: $"<<taxAmount<<endl;
  42. cout<<"Tip Amount: $"<<tipAmount<<endl;
  43. cout<<"Total Bill: $"<<totalBill;
  44.  
  45. //End program
  46. return 0;
  47. }
Success #stdin #stdout 0.01s 5264KB
stdin
Standard input is empty
stdout
Meal Cost: $44.5
Tax Amount: $3.00375
Tip Amount: $6.675
Total Bill: $54.1787