fork download
  1. // This is for calculating sales tax
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main() {
  6. // Purchase amount
  7. double purchase = 52.0;
  8.  
  9. // Tax rates
  10. double stateTaxRate = 0.04; // 4%
  11. double countyTaxRate = 0.02; // 2%
  12.  
  13. // Compute taxes
  14. double stateTax = purchase * stateTaxRate;
  15. double countyTax = purchase * countyTaxRate;
  16. double totalTax = stateTax + countyTax;
  17. double totalAmount = purchase + totalTax;
  18.  
  19. // Display results
  20. cout << "Purchase amount: $" << purchase << endl;
  21. cout << "State tax: $" << stateTax << endl;
  22. cout << "County tax: $" << countyTax << endl;
  23. cout << "Total sales tax: $" << totalTax << endl;
  24. cout << "Total amount with tax: $" << totalAmount << endl;
  25.  
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
Purchase amount: $52
State tax: $2.08
County tax: $1.04
Total sales tax: $3.12
Total amount with tax: $55.12