📜  数组中的总销售额 c++ 二维数组 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:50.255000             🧑  作者: Mango

代码示例2
view sourceprint?
01
#include 
02
using std::cin;
03
using std::cout;
04
using std::endl;
05
 
06
#include 
07
 
08
#include 
09
using std::fixed;
10
using std::setw;
11
using std::setprecision;
12
using std::showpoint;
13
 
14
int main()
15
{
16
    const static int PEOPLE = 5; //number of sales people (4)
17
    const static int PRODUCTS = 6;  //number of different products (5)
18
 
19
    int sales[5][6] = {{1, 2, 3, 4}, {1, 2, 3, 4, 5}};
20
    double value;
21
    double totalSales;
22
    double productSales[PRODUCTS] = {0.0};
23
    int salesPerson;
24
    int product;
25
 
26
    cout << " Enter the salesperson's number (1-4), the product number (1-5), and total product sales.\n "
27
         << "Enter -1 for salesperson to end input.\n";
28
    cin >> salesPerson;
29
 
30
    while (salesPerson != -1)
31
    {
32
        cin >> product >> value;
33
 
34
            value++;
35
         
36
        cin >> salesPerson;
37
    }
38
 
39
    cout << "\nThe total sales for each salesperson are displayed at the "
40
        << "end of each row,\n" << "and the total sales for each product "
41
        << "are displayed at the bottom of each column.\n " << setw( 12 )
42
        << 1 << setw( 12 ) << 2 << setw( 12 ) << 3 << setw( 12 ) << 4
43
        << setw( 12 ) << 5 << setw( 13 ) << "Total\n" << fixed << showpoint;
44
 
45
    for (int i = 1; i < 4; i++)
46
    {
47
        totalSales = 0.0;
48
        cout << i;
49
 
50
        for (int j = 1; j < 5; j++)
51
        {
52
            ++totalSales;
53
 
54
            cout << setw (12) << setprecision (2) << sales [i][j];
55
 
56
            += productSales;
57
        }
58
 
59
        cout << setw (12) << setprecision (2) << totalSales << '\n';
60
   }
61
 
62
    cout << "\nTotal" << setw( 8 ) << setprecision( 2 )
63
      << productSales[ 1 ];
64
 
65
   // display total product sales
66
   for ( int j = 2; j < totalSales; j++ )
67
      cout << setw( 12 ) << setprecision( 2 ) << productSales[ j ];
68
 
69
   cout << endl;
70
    
71
   _getch();
72
}