Guest User

Untitled

a guest
Jun 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. /* This project will ask the user for 5 items and costs of each,
  2. and then output the total price in a neat and tidy table */
  3. // TableProject
  4. // 2-8-12
  5.  
  6. #include <iostream>
  7. #include <iomanip>
  8. using namespace std;
  9.  
  10. int main () {
  11.  
  12. int item1, item2, item3, item4, item5;
  13. double price1, price2, price3, price4, price5, totalItems;
  14. double totalPrice, avgPrice;
  15.  
  16. cout << "\t\tThis program creates a nicely formatted table.\n"
  17. << " By Nessie Murray \n\n";
  18.  
  19. cout << "Quantity of product #1: ";
  20. cin >> item1; cin.ignore(80, '\n');
  21. cout << "Price of product #1: ";
  22. cin >> price1; cin.ignore(80, '\n');
  23. cout << "\n";
  24.  
  25. cout << "Quantity of product #2: ";
  26. cin >> item2; cin.ignore(80, '\n');
  27. cout << "Price of product #2: ";
  28. cin >> price2; cin.ignore(80, '\n');
  29. cout << "\n";
  30.  
  31. cout << "Quantity of product #3: ";
  32. cin >> item3; cin.ignore(80, '\n');
  33. cout << "Price of product #3: ";
  34. cin >> price3; cin.ignore(80, '\n');
  35. cout << "\n";
  36.  
  37. cout << "Quantity of product #4: ";
  38. cin >> item4; cin.ignore(80, '\n');
  39. cout << "Price of product #4: ";
  40. cin >> price4; cin.ignore(80, '\n');
  41. cout << "\n";
  42.  
  43. cout << "Quantity of product #5: ";
  44. cin >> item5; cin.ignore(80, '\n');
  45. cout << "Price of product #5: ";
  46. cin >> price5; cin.ignore(80, '\n');
  47. cout << "\n\n";
  48.  
  49. totalPrice = (item1 * price1) + (item2 * price2) + (item3 * price3)
  50. + (item4 * price4) + (item5 * price5);
  51.  
  52. totalItems = item1 + item1 + item3 + item4 + item5;
  53. avgPrice = (price1 + price2 + price3 + price4 + price5) / 5;
  54.  
  55. cout << " Product # Quantity Price Total\n";
  56. cout << " =======================================================\n"
  57. << setw(9) << "1" << setw(15) << item1 << setw(10) << "$" << setw(8) << fixed << setprecision(2) << price1 << setw(6) << "$" << setw(11) << item1 * price1 << endl
  58. << setw(9) << "2" << setw(15) << item2 << setw(10) << "$" << setw(8) << fixed << setprecision(2) << price2 << setw(6) << "$" << setw(11) << item2 * price2 << endl
  59. << setw(9) << "3" << setw(15) << item3 << setw(10) << "$" << setw(8) << fixed << setprecision(2) << price3 << setw(6) << "$" << setw(11) << item3 * price3 << endl
  60. << setw(9) << "4" << setw(15) << item4 << setw(10) << "$" << setw(8) << fixed << setprecision(2) << price4 << setw(6) << "$" << setw(11) << item4 * price4 << endl
  61. << setw(9) << "5" << setw(15) << item5 << setw(10) << "$" << setw(8) << fixed << setprecision(2) << price5 << setw(6) << "$" << setw(11) << item5 * price5 << endl;
  62. cout << setw(11) << "TOTAL" << setw(14) << totalItems << setw(6) << "$" << setw(7) << fixed << setprecision(2) << avgPrice << setw(10) << totalPrice;
  63. cout << "\n\n";
  64.  
  65.  
  66. system ("pause");
  67. return 0;
  68.  
  69. }
Add Comment
Please, Sign In to add comment