如何總結的數字,在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