fork download
  1. /******************************
  2.  *
  3.  * Task: Ask for the price of an item. Charge 7% sales tax.
  4.  * Print the price, the tax, and the total, with 2 decimals.
  5.  *
  6.  *****************************/
  7.  
  8.  
  9. #include <iostream>
  10. #include <iomanip>
  11. using namespace std;
  12. /******************************************************
  13.   Calculate the price of an item with tax
  14.  
  15.   input : price
  16.  
  17.   output : price, tax, total to 2 decimals
  18. ******************************************************/
  19. int main() {
  20. const double TAX_RATE = 0.07;
  21. double price;
  22.  
  23. //input
  24.  
  25. cout << "enter price of item: $";
  26. cin >> price;
  27.  
  28. //process
  29. int tax = price * TAX_RATE;
  30. int total = price + tax;
  31.  
  32. //output
  33.  
  34. cout << fixed << setprecision;
  35. cout << "Price: $" << price << endl;
  36. cout << "Tax: $" << tax << endl;
  37. cout << "Total: $" << total << endl;
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5288KB
stdin
100
stdout
enter price of item: $1Price: $100.000000
Tax: $7
Total: $107