Jump to content
  • Advertisement
Sign in to follow this  

Problems with array

This topic is 3318 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 <iostream> #include <fstream> #include <iomanip> #include <vector> #include <string> 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; }

Share this post


Link to post
Share on other sites
Advertisement

This topic is 3318 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!