これは経験には明白なことかもしれませんが、C++プログラミングのための私の最初の本当のクラスの真中にあります。私は私のコードの中で、何の成功もなしに解決しようとしている何かを見つけました。これらのクラスモジュールの内部にある配列内に格納されている "m_cost"の合計値の合計を抽出しようとしています。 switch文の中に合計値を出力して印刷したいと思います。誰かが私を正しい方向に向けることができるかどうか、あるいは私が完全にオフ・トラックになったかどうかを見ているだけです。クラスモジュールからの情報を取得してスイッチ文中に出力する際の問題
問題のプロジェクトコードセクション:
void materialsMenu()
{
Inventory record[MAX_REC];
int i, n;
cout << "\n=====Inventory Management=====\n";
cout << "\nHow many Materials are there to be used? : ";
cin >> n;
cout << "Enter " << n << " Materials\n";
for (i = 0; i < n; i++)
record[i].getdata();
cout << "\n\n---Material Information---\n";
cout << "\n" << setw(8) << "Item Name "
<< setw(10) << " Price per foot "
<< setw(19) << " Cost " << endl;
cout << endl << "-------------------------------------------" << endl;
for (i = 0; i < n; i++)
record[i].showdata();
}
void Inventory::getdata() {
cout << endl;
cout << "\nEnter Material Name : ";
cin >> itemName;
cout << "Enter Price Per Foot : ";
cin >> ppf;
cout << "Enter Total Length Needed in Feet (ft) : ";
cin >> length;
cout << endl;
m_cost = ppf*length;
m_costT=???????? **this is the issue**
}
Materials.Hファイルの内容:
#ifndef MATERIALS_H
using namespace std;
class Materials {
private:
char itemName[15];
float ppf;
float length;
double m_cost;
float m_costT;
public:
Materials()
{
ppf = 0;
length = 0;
m_cost = 0;
m_costT = 0;
}
Materials(int itemName, float ppf, float length, double m_cost, float
m_costT)
{
length = getLength();
ppf = getPpf();
m_cost = getCost();
m_costT = getTotal();
}
float getLength()
{
return length;
}
float getPpf()
{
return ppf;
}
double getCost()
{
return m_cost;
}
float getTotal()
{
return m_costT;
}
void getdata();
void showdata();
};
#endif // !MATERIALS_H
本当にあなたの問題を示すために必要のない無関係なコードはありますか? – user0042
問題がどこにあるのか分かりませんでした。すべてを範囲に入れようとしています。 – tex84cl
デバッガ。デバッガを使用します。デバッガを使用すると、コードを一歩一歩進んだり、変数や実行フローの値を見たりすることができます。しばしば、デバッガを使用する方が、StackOverflowに正しくポスティングし、誰かがあなたのコードを検査したり、デバッグするのを待つよりも速いです。デバッグセッションの結果であなたの投稿を編集してください。 –