fork download
  1. // Elaine Torrez CS1A Chapter 2 P. 81, #3
  2.  
  3. /******************************************************************************************
  4.   *
  5.   * CALCULATE SALES TAX
  6.   *
  7.   * --------------------------------------------------------------------------------
  8.   *
  9.   * This program calculates the total sales tax on a $52 purchase.
  10.   * The program uses a state sales tax of 4% and a county sales tax of 2%.
  11.   *---------------------------------------------------------------------------------
  12.   *
  13.   * INPUT
  14.   * purchaseAmount : cost of the item before tax
  15.   * stateTaxRate : 4% (0.04)
  16.   * countyTaxRate : 2% (0.02)
  17.   *
  18.   * OUTPUT
  19.   *
  20.   * stateTax : state sales tax
  21.   * countyTax : county sales tax
  22.   * totalTax : total of state + county taxes
  23.   *
  24.   *******************************************************************************************/
  25.  
  26. #include <iostream>
  27. #include <iomanip> // Included for fixed and setprecision
  28. using namespace std;
  29.  
  30. int main ()
  31. {
  32. double purchaseAmount; // Cost of the purchase before tax
  33. double stateTax; // 4% of the purchase
  34. double countyTax; // 2% of the purchase
  35. double totalTax; // Total tax amount
  36.  
  37. purchaseAmount = 52.00; // INPUT
  38. stateTax = purchaseAmount * 0.04; // Compute state tax
  39. countyTax = purchaseAmount * 0.02;// Compute county tax
  40. totalTax = stateTax + countyTax; // Compute total tax
  41.  
  42. cout << fixed << setprecision(2);
  43.  
  44. // OUTPUT
  45. cout << "Purchase Amount : $" << purchaseAmount << endl;
  46. cout << "State Tax (4%) : $" << stateTax << endl;
  47. cout << "County Tax (2%) : $" << countyTax << endl;
  48. cout << "Total Tax : $" << totalTax << endl;
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Purchase Amount : $52.00
State Tax (4%)  : $2.08
County Tax (2%) : $1.04
Total Tax       : $3.12