Reputation: 762
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;
}
Upvotes: 1
Views: 634
Reputation: 2390
nekaj::nastavi_izracunaj_izpisi();
// should be
nekaj.nastavi_izracunaj_izpisi();
It's the right way to call a method. Or to access a member (as @Ben Voigt said).
// Tehre an integer division by 0 on this line
produkti = rand() % i + 200;
// because this line always return 0
i = rand() % 100; // Koliko računov smo imeli.
Upvotes: 2