Original Post
Hello! I'm working on the following project, it is working to compile, but i get some strange numbers on my array in _kategori, can anybody please help or point me at the right direction to fix this problem. the problem is that for each kategori will be asigned a specifik value and if you add a new kategorie it should add that currency to that kategorie in the array. #include #include #include #include #include using namespace std; class Test { public: Test ( char* filnamn, int antalKategorier ); ~Test(); bool regist ( int kategori, string name, double currency ); void calc(int kategori, double currency); private: ofstream _fil; int _numberKategori; double _kategori[100]; }; Test::Test ( char* filnamn, int numberKategorier ){ _fil.open(filnamn, ios::app); if (!_fil.is_open()) cout << "filen kunde ej öppnas" << endl; _numberKategori = numberKategorier; _fil << ">>>>> Register opened:" << endl; } Test::~Test(){ _fil << ">>>>> Register closed: " << endl; _fil << "Category totals for last opening period: " << endl; _fil << "-----------------------------------------" << endl; for (int i = 1; i <= _numberKategori; i++){ _fil << "Category " << i << " : " << _kategori << " kr" << endl; } _fil.close(); } bool Test::regist ( int kategori, string artikelnamn, double currency ){ if ( ( kategori > 0 ) && ( kategori <= _numberKategori ) ){ _fil << "cat. " << kategori << " : " << currency << " [ " << artikelnamn << " ]" << endl; calc(kategori, currency); return true; } else return false; } void Test::calc(int kategori, double currency){ _kategori[kategori] += currency; } int main() { Test open ( "Register.txt", 5 ); if (!open.regist( 1,"Äppelmos Bob", 14.50 )) cout << "don't work" << endl; if (!open.regist( 1,"Coca Cola 2 lit.", 12.00 )) cout << "don't work" << endl; return 0; }