Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using std::cout;
  5. using std::cin;
  6. using std::endl;
  7. using std::fixed;
  8. using std::setprecision;
  9. using std::setw;
  10. using std::left;
  11.  
  12. int main()
  13. {
  14. double sales[4][5] = {
  15. {0,0,0,0,0},
  16. {0,0,0,0,0},
  17. {0,0,0,0,0},
  18. {0,0,0,0,0}
  19. };
  20.  
  21. int salesPerson = 0;
  22. int product = 0;
  23. double value = 0;
  24.  
  25. while(true) {
  26. cout << "Enter the salesperson, product, and total sales." << endl;
  27. cout << "(Enter -1 for the salesperon to end input): ";
  28.  
  29. cin >> salesPerson;
  30.  
  31. if(!cin || (salesPerson < 1 && salesPerson != -1) || salesPerson > 4) {
  32. cout << "Sales person should be between 1 and 4" << endl;
  33. continue;
  34. }
  35. else if(salesPerson == -1) {
  36. break;
  37. }
  38.  
  39. cin >> product;
  40.  
  41. if(!cin || product < 1 || product > 5) {
  42. cout << "Product should be between 1 and 5" << endl;
  43. continue;
  44. }
  45.  
  46. cin >> value;
  47.  
  48. if(!cin || value < 0) {
  49. cout << "Value should be a positive floating-point number" << endl;
  50. break;
  51. }
  52.  
  53. sales[salesPerson-1][product-1] += value;
  54. }
  55.  
  56. cout << setw(8) << left << "Sales" << setw(36) << left << "Products" << endl;
  57. cout << setw(8) << left << "Person";
  58.  
  59. for(int i = 0; i < 5; i++) {
  60. cout << setw(8) << left << (i+1);
  61. }
  62.  
  63. cout << setw(6) << left << "Total" << endl;
  64.  
  65. double productsTotal[4] = {0,0,0,0};
  66.  
  67. for(int i = 0; i < 4; i++) {
  68. cout << setw(8) << left << (i+1);
  69. double salesPersonTotal = 0;
  70.  
  71. for(int j = 0; j < 5; j++) {
  72. salesPersonTotal += sales[i][j];
  73. productsTotal[j] += sales[i][j];
  74.  
  75. cout << setw(8) << left;
  76. cout << fixed << setprecision(2) << sales[i][j];
  77. }
  78.  
  79. cout << setw(6) << left << salesPersonTotal << endl;
  80. }
  81.  
  82. cout << setw(8) << left << "Total";
  83. for(int i = 0; i < 5; i++) {
  84. cout << setw(8) << left;
  85. cout << fixed << setprecision(2) << productsTotal[i];
  86. }
  87.  
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement