fork download
  1. //Devin Scheu CS1A Chapter 2, P. 81, #3
  2. //
  3. /**************************************************************
  4. *
  5. * CALCULATE TOTAL SALES TAX
  6. * ____________________________________________________________
  7. * This program calculates the totalSalesTax given a
  8. * totalCost, a stateTaxPercentage and a countyTaxPercentage.
  9. *
  10. * Computation is based on the formula:
  11. * totalSalesTax = ((stateTaxPercentage / 100) * totalCost) + ((countyTaxPercentage / 100) * totalCost)
  12. * ____________________________________________________________
  13. * INPUT
  14. * totalCost : Total cost of purchase in dollars (as a double 23.76)
  15. * stateTaxPercentage : Percentage of state sales tax (as a double: 4.7)
  16. * countyTaxPercentage : Percentage of county sales tax (as a double: 2.8)
  17. *
  18. * OUTPUT
  19. * totalSalesTax : The amount of tax paid (in dollars: $4.57)
  20. *
  21. **************************************************************/
  22.  
  23. #include <iostream>
  24. #include <iomanip>
  25.  
  26. using namespace std;
  27.  
  28. int main () {
  29.  
  30. //Variable Declarations
  31. double totalCost; //INPUT - Total cost of purchase in dollars (as a double 23.76)
  32. double stateTaxPercentage; //INPUT - Percentage of state sales tax (as a double: 4.7)
  33. double countyTaxPercentage; //INPUT - Percentage of county sales tax (as a double: 2.8)
  34. double totalSalesTax; //OUTPUT - The amount of tax paid (in dollars: $4.57)
  35.  
  36. //Variable Initialization
  37. totalCost = 52;
  38. stateTaxPercentage = 4;
  39. countyTaxPercentage = 2;
  40.  
  41. //Calculate Sales Generated
  42. totalSalesTax = ((stateTaxPercentage / 100) * totalCost) + ((countyTaxPercentage / 100) * totalCost);
  43.  
  44. //Output Result
  45. cout << fixed << setprecision(2) << "The total sales tax is: $" << totalSalesTax << endl;
  46.  
  47. } //end of main()
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
The total sales tax is: $3.12