問題は、3ヵ月を組み合わせることで各従業員の合計売上を与える1から10までの従業員番号(彼らは配列に入る配列番号を与えました)を求めていました。私の追加機能では、すべて正常に処理されます。最初の部分は...配列の数字は完全に表示されますが、配列を追加するときには数字が表示され、ここでは正しくない合計が返されます。私のコードでは、配列番号に最初に付いた配列番号の後に、配列に続く配列に続く配列番号を付けるべきであると付け加えました。2次元配列の追加問題
私は、 btw)、残りの部分に従業員#1の合計を追加しています。これはやりたくありません。私は従業員#1のお互いに入力したいそれを表示して停止してから、3ヶ月の3つの数字から従業員#2の合計を追加する配列の表示を停止する(各部分が1から10まで表示されるまで続ける)新しいコードを入力する。私はC++プログラミングが初めてで、クラスについてまだ学んでいないので、正直なところ使用できません。
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
void displaySales(int sales[10][3]);
void displayTotalSales(int total[10][3]);
int main()
{
//declare array Jan Feb Mar
int employ[10][3] = {{2400, 3500, 2000},
{1500, 7000, 1000},
{600, 450, 2100},
{790, 240, 500},
{1000, 1000, 1000},
{6300, 7000, 8000},
{1300, 450, 700},
{2700, 5500, 6000},
{4700, 4800, 4900},
{1200, 1300, 400}};
//displays the sales for the month
displaySales(employ);
displayTotalSales(employ);
system("pause");
return 0;
}
//******Functions*******
void displaySales(int sales[10][3])
{
for(int emp = 0; emp < 10; emp++)
{
cout << "Employee # " << emp + 1
<< ": " << endl;
for (int month = 0; month < 3; month++)
{
cout << " Month " << month + 1
<< ": ";
cout << sales[emp][month] << endl;
} //end for
} //end for
} //end function
void displayTotalSales(int total[10][3])
{
int employ = 1; //employee number
int totalSales = 0; // total sales for the employee
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 3; j++)
{
totalSales += total[i][j];
cout << "Employee # " << employ << ": " << endl;
cout << endl;
cout << "Total sales for the month: " << "$" << total[i][j];
cout << endl;
}
cout << " Total Sales for the three months is: $" << totalSales << endl;
cout << endl;
employ++;
}
}
なぜ、従業員1人につき3回追加していますか? –
編集にコードをコピーすると、インデントが移動してしまいます。このような不便は残念です。 – Rootz
クロムを使用している場合は、テキストエリア内のテキストを選択し、タブを押してインデント(テキストエリアフォーマッタ)するだけの素晴らしい拡張機能があります。 – 6502