I get this error, so I got this suggestion to try methods... I had an epic fail. This is my code, I don't know what I'm doing wrong, please explain and correct me, I want to learn, not just fix the problem:
#include <iostream> #include <string> #include <stdlib.h> #include <windows.h> using namespace std; class datum { public: int leto; int mesec; int dan; }; class racun { string naslov; float cena; // Skupna cena na računu int i; // Števec public: datum izdaje; //racuna void nastavi_izracunaj_izpisi() { izdaje.dan = rand() % 30 + 1; //Dan izdaje.mesec = rand() % 12 + 1; //Mesec izdaje.leto = rand() % 30 + 1985; //Leto i = rand() % 100; // Koliko računov smo imeli. int produkti; produkti = rand() % i + 200; //Koliko produktov smo imeli int produkt1[200]; //cena prvega produkta int produkt2[200]; //cena drugega produkta int a; //števec produktov a=0; //ki ga nastavimo na nič do { produkt1[a] = rand() % 200; produkt2[a] = rand() % 200; a=a+1; }while(a!=produkti); int b; //kateri produkt bo izpisalo b = rand() % 200; cout<<"Kupili ste:"<<produkti<<" produktov"<<endl; //izpis za produkte do { cena=produkt1[b]+produkt2[b]; i++; }while(i!= produkti); cout<<"Cena računa brez ddv je: "<<cena<<endl; //DDV float ddv = 1.12797374897; float cena2; float cenaddv; cena2=cena/ddv; cenaddv=cena+cena2; cout<<"Cena računa z ddv je: "<<cenaddv<<endl; } }; int main() { racun nekaj; nekaj::nastavi_izracunaj_izpisi(); //Nena dela, FAG system("PAUSE"); return 0; }
nekaj::nastavi_izracunaj_izpisi()should benekaj.nastavi_izracunaj_izpisi()- you're calling a member function on an object.::is used for static member function, with the class name rather than the object name as prefix.std::coutstatements throughout the code until you can see exactly which line is crashing (because the output from the prior line's shown, but not the following line). If you can't work out why it crashes there, then ask us. Alternatively, use an interactive debugger like gdb or Visual Studio's.