﻿

# CW #9

Dec 5th, 2019
114
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include <iomanip>
3. using namespace std;
4.
5. const int PEOPLE = 5, PRODUCTS = 6;
6. double sales[PEOPLE][PRODUCTS] = {0,0}, value, totalSales, productSales[PRODUCTS] = {0,0};
7. int salesPerson, product, i = 1;
8.
9. void salesInput() {
10. do {
11. cin >> salesPerson;
12. if (salesPerson != -1) {
13. cin >> product >> totalSales;
14. }
15. sales[salesPerson][product] = totalSales;
16. } while (salesPerson != -1);
17. }
18.
19. void salesOutput() {
20. cout << setw(10) << "1" << setw(10) << "2" << setw(10) << "3" << setw(10) << "4" << setw(10) << "5" << setw(11) << "Total" << endl;
21.
22. for (int i = 1; i < PEOPLE; ++i ) {
23. cout << i;
24. cout << setw(10) << fixed << setprecision(2) << sales[i][1];
25. cout << setw(10) << fixed << setprecision(2) << sales[i][2];
26. cout << setw(10) << fixed << setprecision(2) << sales[i][3];
27. cout << setw(10) << fixed << setprecision(2) << sales[i][4];
28. cout << setw(10) << fixed << setprecision(2) << sales[i][5];
29. cout << setw(10) << fixed << setprecision(2) << sales[i][1] + sales[i][2] + sales[i][3] + sales[i][4] + sales[i][5] << endl;
30. }
31.
32. cout << endl << "Total";
33. cout << setw(6) << sales[1][1] + sales[2][1] + sales[3][1] + sales[4][1];
34. cout << setw(10) << sales[1][2] + sales[2][2] + sales[3][2] + sales[4][2];
35. cout << setw(10) << sales[1][3] + sales[2][3] + sales[3][3] + sales[4][3];
36. cout << setw(10) << sales[1][4] + sales[2][4] + sales[3][4] + sales[4][4];
37. cout << setw(10) << sales[1][5] + sales[2][5] + sales[3][5] + sales[4][5];
38. }
39.
40. int main() {
41. cout << "Enter the sales person (1 - 4), product number (1 - 5) and total sales. Enter -1 for the sales person to end input." << endl << endl;
42.
43. salesInput();
44. salesOutput();
45.
46. return 0;
47. }
RAW Paste Data