如何总结的数字,在C++ 阵列中的一个排,以及如何添加所有的数字数组中如何总结在C++中的数组
我尝试过很多办法的一行数字和这是我能想到的最后一种可能性。 我是编程新手。
这是代码的这个问题
const int NUM_SALESPEOPLE = 4;
const int NUM_PRODUCTS = 3;
const int NUM_TOTALS = 0;
int main()
{
unsigned __int64 id_numbers[NUM_SALESPEOPLE]; //>>>>> usigned __int64 is used in case the company have id numbers that consest of 10 digits and startr's with a 9
double sales_amount[NUM_SALESPEOPLE][NUM_PRODUCTS];
float sales_people[NUM_SALESPEOPLE][NUM_PRODUCTS];
double sales_total[NUM_SALESPEOPLE][1];
int total_counter = 0;
int sales_total_counter = 0;
//input
for (int id_counter = 0; id_counter < NUM_SALESPEOPLE; id_counter++)
{
cout << "Enter the ID # of Salesperson # " << id_counter + 1 << " :";
cin >> id_numbers[id_counter];
for (int sales_counter = 0; sales_counter < NUM_PRODUCTS; sales_counter++)
{
cout << "Enter the Dollar value for the Sale of Product # " << sales_counter + 1 << " :";
cin >> sales_amount[id_counter][sales_counter];
}
}
//Processing
sales_total[0][1] += sales_amount[0][0];
sales_total[1][1] += sales_amount[0][1];
sales_total[2][1] += sales_amount[0][1];
return 0;
}
该示例缺少所有上下文。您将添加到不同的条目中,而不是单个总额,并且您正在读取'sales_amount [0] [1]'两次。 – ShadowRanger