我的数组应该为3个销售人员接受3个值,存储并打印该数组,但不知为何我无法理解它。我对c ++ 2d数组不太熟悉,所以这对我来说有点新。
#include<iostream>
using namespace std;
int main( )
{
const int salesPersonCount =3, productCount = 3;
int rows = 5, colums = 5;
int sales[rows][columns];
int i, j, m;
double total;
for (int p = 1; p <= salesPersonCount; p++){
cout<< "\n \n Information for SalesPsn"<< p <<" : \n \n";
//Sales Person
for (int m = 1; m <=productCount; m++){
//Product Number
cout<< "\n Please enter sales value of product "<< m << ":";
cout << "\n ";
for(i=0;i<rows;i++)
{
for(j=3;j<columns;j++){
cout<<"\nThe 2-D Array is:\n";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<"\t"<<s[i][j];
} cout<< "Sale " << setw (17) << "Salespsn1" << setw (22)<< "Salespsn2"
<< setw (27)<< "Salespsn3" << setw (32) << "Total" << endl;
}
cout<<endl;
}
return 0;
}
我必须清理很多代码才能使它甚至开始编译。在许多情况下,不存在块的关闭}
。这些错误很容易犯,但如果您关于保持一致的缩进样式的纪律。
一旦我缩进代码,错误在哪里就变得很明显了,但是要在原始代码中识别它们非常困难。
这里是清理代码:
#include <iostream>
#include <iomanip>
int main( ) {
const int salesPersonCount =3, productCount = 3;
int rows = 5, columns = 5;
int sales[rows][columns];
double total;
for (int p = 1; p <= salesPersonCount; p++) {
std::cout << "\n \n Information for SalesPsn"<< p <<" : \n \n";
//Sales Person
for (int m = 1; m <=productCount; m++) {
//Product Number
std::cout << "\n Please enter sales value of product "<< m << ":";
std::cout << "\n ";
for (int i=0;i<rows;i++) {
for (int j=3;j<columns; j++) {
std::cout << "\nThe 2-D Array is:\n";
for (int i=0;i<2;i++) {
for (int j=0;j<2;j++) {
std::cout << "\t" << sales[i][j];
}
std::cout << "Sale " << std::setw (17) << "Salespsn1" << std::setw (22)<< "Salespsn2"
<< std::setw (27)<< "Salespsn3" << std::setw (32) << "Total" << std::endl;
}
std::cout << std::endl;
}
}
}
}
return 0;
}
请注意,这仍然有lot个您需要解决的问题,例如如何将销售和信息捕获到变量p
和m
中,这些变量[