fork download
  1. //Zachary Abdollahi CS1A Chapter 2, P. 81, #3
  2. //
  3. /***************************************************************************
  4.  *
  5.  * COMPUTE TOTAL SALES TAX
  6.  * _________________________________________________________________________
  7.  * This program computes the total sales tax on a purchase based on
  8.  * the sales tax and county sales tax rates.
  9.  *
  10.  * Computation is based on the formulas:
  11.  * State Tax = Purchase Amount x Sales Tax Rate
  12.  * County Tax = Purchase Amount x County Tax Rate
  13.  * Total Tax = Sales Tax + County Tax
  14.  * _________________________________________________________________________
  15.  * INPUT
  16.  * purchaseAmount : Total amount of the purchase ($52)
  17.  * salesTaxRate : State sales tax percentage (4%)
  18.  * countyTaxRate : County sales tax percentage (2%)
  19.  *
  20.  * OUTPUT
  21.  * stateTax : Amount of state sales tax
  22.  * countyTax : Amount of county sales tax
  23.  * totalTax : Total sales tax calculated
  24.  *
  25.  **************************************************************************/
  26. #include <iostream>
  27. #include <iomanip>
  28. using namespace std;
  29.  
  30. int main()
  31. {
  32. float purchaseAmount; //INPUT - Purchase amount in dollars
  33. float stateTaxRate; //INPUT - State tax rate percentage
  34. float countyTaxRate; //INPUT - County tax rate percentage
  35. float stateTax; //OUTPUT - Calculated state tax
  36. float countyTax; //OUTPUT - Calculated county tax
  37. float totalTax; //OUTPUT - Calculated total sales tax
  38.  
  39. // Initialize Program Variables
  40. purchaseAmount = 52.0;
  41. stateTaxRate = 0.04;
  42. countyTaxRate = 0.02;
  43.  
  44. // Compute Taxes
  45. stateTax = purchaseAmount * stateTaxRate;
  46. countyTax = purchaseAmount * countyTaxRate;
  47. totalTax = stateTax + countyTax;
  48.  
  49. // Output Result
  50. cout << fixed << setprecision(2);
  51. cout << "State Sales Tax: $" << stateTax << endl;
  52. cout << "County Sales Tax: $" << countyTax << endl;
  53. cout << "Total Sales Tax: $" << totalTax << endl;
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
State Sales Tax:  $2.08
County Sales Tax: $1.04
Total Sales Tax:  $3.12