fork download
  1. // Cameron Pham CS1A chapter 2, p. 82, #8
  2. //
  3. /******************************************************************************
  4.  *
  5.  * Displaying Item Prices, Subtotal of Sale, Amount of Sales Tax, and Total Cost
  6.  *
  7.  * _____________________________________________________________________________
  8.  * This program computes and displays a customer's purchase in a store
  9.  * purchase five items. It displays the prices of five items, computes the
  10.  * subtotal of the sale, amount of sales tax, and the total cost of the sale.
  11.  *
  12.  * Computation is based on the formula:
  13.  * subtotalSale = item1 + item2 + item3+ item4 + item5
  14.  * salesTaxAmount = subtotalSale * salesTax
  15.  * totalSale = subtotalSale + salesTaxAmount
  16.  * _____________________________________________________________________________
  17.  * INPUT
  18.  * item1 = $12.95 (cost of item)
  19.  * item2 = $24.95 (cost of item)
  20.  * item3 = $6.95 (cost of item)
  21.  * item4 = 14.95 (cost of item)
  22.  * item5 = $3.95 (cost of item)
  23.  * salesTax = 6% (tax rate percentage)
  24.  *
  25.  * OUTPUT
  26.  * subtotalSale = charge of all items before tax
  27.  * salesTaxAmount = charge of tax
  28.  * totalSale = charge of items after tax is added
  29.  *
  30.  * ****************************************************************************/
  31. #include <iostream>
  32. using namespace std;
  33.  
  34. int main() {
  35. double item1; // INPUT - The cost of item
  36. double item2; // INPUT - The cost of item
  37. double item3; // INPUT - The cost of item
  38. double item4; // INPUT - The cost of item
  39. double item5; // INPUT - The cost of item
  40. double salesTax; //INPUT - tax rate percentage
  41. double subtotalSale; // OUTPUT - The sale cost before tax
  42. double salesTaxAmount; // OUTPUT - The charge of tax
  43. double totalSale; // OUTPUT - The total sale cost after tax
  44.  
  45. // Initializing Program Variables
  46. item1 = 12.95;
  47. item2 = 24.95;
  48. item3 = 6.95;
  49. item4 = 14.95;
  50. item5 = 3.95;
  51. salesTax = 0.06;
  52.  
  53. // Computing Sales
  54. subtotalSale = item1 + item2 + item3 + item4 + item5;
  55. salesTaxAmount = subtotalSale * salesTax;
  56. totalSale = subtotalSale + salesTaxAmount;
  57.  
  58. // Final Output
  59. cout << "Price of item 1 = $ " << item1 << endl;
  60. cout << "Price of item 2 = $ " << item2 << endl;
  61. cout << "Price of item 3 = $ " << item3 << endl;
  62. cout << "Price of item 4 = $ " << item4 << endl;
  63. cout << "Price of item 5 = $ " << item5 << endl;
  64. cout << "Subtotal = $ " << subtotalSale << endl;
  65. cout << "Amount of sales tax = $ " << salesTaxAmount << endl;
  66. cout << "Total cost = $ " << totalSale << endl;
  67.  
  68. return 0;
  69. }
Success #stdin #stdout 0.01s 5232KB
stdin
Item 
stdout
Price of item 1 = $ 12.95
Price of item 2 = $ 24.95
Price of item 3 = $ 6.95
Price of item 4 = $ 14.95
Price of item 5 = $ 3.95
Subtotal = $ 63.75
Amount of sales tax = $  3.825
Total cost = $ 67.575