fork download
  1. // adhira b cs1a ch 2 hw
  2. /*******************************************************************************
  3. *calculate total cost of five items.
  4. *
  5. *__________________________________________________________
  6. * sums up 5 costs to calculate the total cost, then adds 6% tax
  7. *____________________________________________________________
  8. *INPUT
  9. * item_1 - cost of item 1
  10. * item_2 - cost of item 2
  11. * item_3 - cost of item 3
  12. * item_4 - cost of item 4
  13. * item_5 - cost of item 5
  14. * Total - sum of all
  15. *OUTPUT
  16. * code adds then prints the total purchase amount.
  17. *******************************************************************************/
  18. #include <iostream>
  19. #include <string>
  20. using namespace std;
  21.  
  22. int main ()
  23. {
  24. //initialize 5 items.
  25.  
  26. float item_1;
  27. float item_2;
  28. float item_3;
  29. float item_4;
  30. float item_5;
  31.  
  32.  
  33. //5 prices input
  34.  
  35. cin.ignore();
  36. cout << "how much is item one? " << endl;
  37. cin >> item_1;
  38.  
  39. cout << "how much is item two? " << endl;
  40. cin >> item_2;
  41.  
  42. cout << "how much is item three? " << endl;
  43. cin >> item_3;
  44.  
  45. cout << "how much is item four? " << endl;
  46. cin >> item_4;
  47.  
  48. cout << "how much is item five? " << endl;
  49. cin >> item_5;
  50.  
  51.  
  52. //calculate Total
  53.  
  54. float subtotal = item_1 + item_2 + item_3 + item_4 + item_5;
  55. float tax = subtotal * .06;
  56. float Total = subtotal + tax;
  57. //Print out subtotal, tax, then total of five items.
  58.  
  59. cout << "subtotal: $" << subtotal << endl;
  60. cout << "tax: $" << tax << endl;
  61. cout << "total: $" << Total << endl;
  62. return 0;
  63. }
  64.  
Success #stdin #stdout 0.01s 5324KB
stdin
12.95
24.95
6.95
14.95
3.95
stdout
how much is item one? 
how much is item two? 
how much is item three? 
how much is item four? 
how much is item five? 
subtotal: $53.75
tax: $3.225
total: $56.975