fork download
  1. //Charlotte Davies-Kiernan CS1A Chapter 2 P.82 #3
  2. //
  3. /******************************************************************************
  4.  *
  5.  * Compute Sales Tax
  6.  * ____________________________________________________________________________
  7.  * This program calculates the total sales tax on an item assuming the
  8.  * state sales tax and county sales tax are the percentages given
  9.  *
  10.  * Computation is based on the formulas:
  11.  * sale total = purchase amount + total tax
  12.  * ____________________________________________________________________________
  13.  * INPUT
  14.  * purchaseAmount : Price of item before any tax added
  15.  * stateTaxRate : Percentage of state tax
  16.  * countyTaxRate : Percentage of county tax
  17.  *
  18.  * OUTPUT
  19.  * stateTax : Amount of tax that will be added from state
  20.  * countyTax : Amount of tax that will be added from county
  21.  * totalTax : Constant for state and county tax added together
  22.  * totalAmount : Price of purchase with everything included
  23.  *****************************************************************************/
  24. #include <iostream>
  25. #include <iomanip>
  26. using namespace std;
  27. int main()
  28. {
  29. float purchaseAmount; //INPUT - price of item with nothing added
  30. float stateTaxRate; //INPUT - Percentage of state tax
  31. float countyTaxRate; //INPUT - Percentage of county tax
  32. float stateTax; //OUTPUT - Amount of tax from state
  33. float countyTax; //OUTPUT - Amount of tax from county
  34. float totalTax; //OUTPUT - Amount of tax from both state and county
  35. float totalAmount; //OUTPUT - Price of purchase with everything included
  36. //
  37. // Initialize Program Variables
  38. purchaseAmount = 52.0;
  39. stateTaxRate = 0.04;
  40. countyTaxRate = 0.02;
  41. //
  42. // Compute Amount for State Tax
  43. stateTax = purchaseAmount * stateTaxRate;
  44. //
  45. // Output Result
  46. cout << "State Sales Tax : $" << stateTax << endl;
  47. //
  48. // Compute Amount for County Tax
  49. countyTax = purchaseAmount * countyTaxRate;
  50. //
  51. // Output Result
  52. cout << "County Sales Tax: $" << countyTax << endl;
  53. //
  54. // Compute Total Tax Amount
  55. totalTax = stateTax + countyTax;
  56. //
  57. // Output Result
  58. cout << "Total Tax: $" << totalTax << endl;
  59. //
  60. // Comput Final Sale Price
  61. totalAmount = purchaseAmount + totalTax;
  62. //
  63. // Output Result
  64. cout << "Total Amount due: $" << totalAmount << endl;
  65. return 0;
  66. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
State Sales Tax : $2.08
County Sales Tax: $1.04
Total Tax: $3.12
Total Amount due: $55.12