看下这个c++的程序题目,哪儿错 了呢,帮忙找下错误

用二维数组来解决此问题。公司有4位销售员(1到4),销售5种不同的商品(1到5),每位销售员每天都以表单的形式记录销售的产品。每份单据包含以下内容:a)销售员代号b)产品... 用二维数组来解决此问题。公司有4位销售员(1到4),销售5种不同的商品(1到5),每位销售员每天都以表单的形式记录销售的产品。每份单据包含以下内容:

a)销售员代号

b)产品代号

c)产品的当天销售额

因此,每位销售员每天可能要记录0到5个单据,假定我们可以得到上个月里所有单据的信息,那么我们来编写程序,读入所有的信息,并计算每位销售员销售每件产品的总销售额。总和将存储在一个名为sales的二维数组中。在处理了上个月的所有信息后,将结果以表的形式打印出来,列代表产品,行代表销售员。列的和为每件产品的总销售额,行的和为每位销售员销售产品的总销售额。表单的打印输出应包含这些内容,在每行的右端计算此行的和,在每列的下端计算此列的和。

实例输出

Enter the sales person (1 - 4),product number (1 - 5)

and total sales.Enter -1 for the sales person to end input.

1 1 9.99

3 3 5.99

2 2 4.99

-1

The total sales for each sales person are displayed

at the end of each row, and the total sales for each

product are displayed at the bottom of each column.

1 2 3 4 5 Total

1 9.99 0.00 0.00 0.00 0.00 9.99

2 0.00 4.99 0.00 0.00 0.00 4.99

3 0.00 0.00 5.99 0.00 0.00 5.99

4 0.00 0.00 0.00 0.00 0.00 0.00

Total 9.99 4.99 5.99 0.00 0.00

using namespace std;

int main()
{
const int PEOPLE = 5, PRODUCTS = 6;
double sales[PEOPLE][PRODUCTS]={0.00};
double value, totalSales, productSales[PRODUCTS] = { 0.0 };
int salesPerson, product;
cout << "Enter the sales person (1-4), "
<< "product number (1-5)\nand total sales."
<< "Enter -1 for the sales person to end input.\n";
cin >> salesPerson;
while( salesPerson != -1)
{
cin >> product >> value;//产品 价值
cin >> salesPerson;//售货员
sales[salesPerson][product] =value;
} cout<< "are displayed\nat the end of each row,"
<< "and the total sales for each\nproduct "
<< "are displayed at the bottom of each column."<<endl

<< setw(10) << 1 << setw(10) << 2
<< setw(10) << 3 << setw(10) << 4
<< setw(10) << 5 << setw(12) << "Total\n"
<< setiosflags( ios::fixed | ios:: showpoint );
for( int i = 1;i<5 ; ++i )
{
totalSales = 0.0;//销售总额
cout << i;
for (int j = 1; j<6; ++j )
{
cout << setw(10) << setprecision(2)
<< sales[i][j];
totalSales+=sales[i][j];

}
productSales[i]=totalSales;
cout << setw(10) << setprecision(2)
<< totalSales << '\n';
}
cout << "\nTotal" << setw(6) << setprecision(2)
<< productSales[1];

for( int j = 2; j < PRODUCTS; ++j )
cout << setw(10) << setprecision(2)
<< productSales[j];

cout << endl;
return 0;
}
展开
 我来答
官锶帅是狸1B
2017-04-22 · TA获得超过2038个赞
知道小有建树答主
回答量:323
采纳率:100%
帮助的人:85.1万
展开全部
#include<iostream>
#include <iomanip>
using namespace std;

int main()
{
    const int PEOPLE = 5, PRODUCTS = 6;
    double sales[PEOPLE][PRODUCTS]={0.00};
    double value, totalSales, productSales[PRODUCTS] = { 0.0 };
    int salesPerson, product;
    int i,j;

    cout << "Enter the sales person (1-4), "
    << "product number (1-5)\nand total sales."
    << "Enter -1 for the sales person to end input.\n";

    cin >> salesPerson;
    while( salesPerson != -1)
    {
        cin >> product >> value;//产品 价值

        sales[salesPerson][product] =value; //sales[][]应该放这里

        cin >> salesPerson;//售货员
        //sales[][]语句放错了位置,导致所有数据的位置不对
        //原代码 sales[salesPerson][product] =value;
    }
    cout<< "are displayed\nat the end of each row,"
    << "and the total sales for each\nproduct "
    << "are displayed at the bottom of each column."<<endl
    << setw(10) << 1 << setw(10) << 2
    << setw(10) << 3 << setw(10) << 4
    << setw(10) << 5 << setw(12) << "Total\n"
    << setiosflags( ios::fixed | ios:: showpoint );
    //原代码for( int i = 1;i<5 ; ++i )
    for( i = 1;i<PEOPLE ; ++i )
    {
        totalSales = 0.0;//销售总额
        cout << i;
        //原代码for (int j = 1; j<6; ++j )
        for (j = 1; j<PRODUCTS; ++j )
        {
            cout << setw(10) << setprecision(2)
            << sales[i][j];

            totalSales += sales[i][j];  //每位销售员的(5种商品)销量合计

            productSales[j] += sales[i][j]; //每种商品的(4位销售员)销量合计
        }
        //原代码productSales[i]=totalSales;
        cout << setw(10) << setprecision(2)
        << totalSales << '\n';
    }
    cout << "\nTotal" << setw(6) << setprecision(2)<< productSales[1];
    //原代码for( int j = 2; j < PRODUCTS; ++j )
    for(j = 2; j < PRODUCTS; ++j )
    {
       cout << setw(10) << setprecision(2) << productSales[j];
    }
    cout << endl;
    return 0;
}

更多追问追答
追问
在?
可以运行?
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式