fork download
  1. //Andres Guzman CSC5 Chapter 2, P. 82, #8
  2. //
  3. /**************************************************************
  4. *
  5. * COMPUTE TOTAL SALE OF 5 ITEMS
  6. * ____________________________________________________________
  7. * This program computes the total price of items after taxes
  8. *
  9. * Computation is based on the formulas:
  10. * subtotal = item1 + item2 + item3 + item4 + item5
  11. * total = (subtotal * tax) + subtotal
  12. * ____________________________________________________________
  13. * INPUT
  14. * item1 -> item5 : Price of item
  15. * tax : Tax after subtotal of items
  16. * OUTPUT
  17. * subtotal : Sum of all items
  18. * total : Sum including tax
  19. **************************************************************/
  20. #include <iostream>
  21. #include <iomanip>
  22. using namespace std;
  23. int main ()
  24. {
  25. double item1; //Input Price
  26. double item2; //Input Price
  27. double item3; //Input Price
  28. double item4; //Input Price
  29. double item5; //Input Price
  30. double tax; //Input Tax Precentage
  31. double subtotal; //Output Sum of all Items
  32. double total; //Output Total sum with Tax
  33. //
  34. //Initializing Variables
  35. item1 = 12.95;
  36. item2 = 24.95;
  37. item3 = 6.95;
  38. item4 = 14.95;
  39. item5 = 3.95;
  40. tax = 0.06;
  41. //
  42. //Computing Formulas
  43. subtotal = item1 + item2 + item3 + item4 + item5;
  44. total = (subtotal * tax) + subtotal;
  45. //
  46. //Output Results
  47. cout << "Item 1: $" << item1 << endl;
  48. cout << "Item 2: $" << item2 << endl;
  49. cout << "Item 3: $" << item3 << endl;
  50. cout << "Item 4: $" << item4 << endl;
  51. cout << "Item 5: $" << item5 << endl;
  52. cout << fixed << setprecision(2) << "Subtotal: $" << subtotal << endl;
  53. cout << fixed << setprecision(0) << "Sale Tax: " << tax*100 << "%" << endl;
  54. cout << fixed << setprecision(2) << "Total: $" << total << endl;
  55. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Item 1: $12.95
Item 2: $24.95
Item 3: $6.95
Item 4: $14.95
Item 5: $3.95
Subtotal: $63.75
Sale Tax: 6%
Total: $67.58