im trying to make a variable in a class which changes and doesnt start over from the initial value ... for example if i have int quantity = 500 and subtract 100 the new value will be 400 then i subtract 100 and new value will be 300 ... etc how owuld i go about doing this.. i tried using static int but it gave me errors
heres my class
Code:
class sales
{
public:
//default constructor
sales();
//mutator member functions
void setCustomer(string custom);
void setProduct(string prod);
void setQuantity(int qua);
void setMonth(int m);
void setDay(int d);
void setYear(int y);
void setValid(bool a);
void setFTime(bool a);
void setTotal(int tot);
void setFirst(int a);
//accessor member functions
bool getValid();
bool getFTime();
int getMonth();
int getDay();
int getYear();
string getCustomer();
string getProduct();
int getQuantity();
int getTotal();
int getFirst();
int checkDay(int); //utility function to test proper day for month and year
protected:
//data members
string customerNum;
string productName;
int quantity;
bool valid;
bool ftime;
int month; //1-12
int day;//1-31 based on month
int year;//any year
int total;
int first;
};
class ProductManager: public sales
{
public:
string productName1;
float price;
static int quantity;
};
ProductManager store[40];
the code that im having trouble with
Code:
int h = num_lines("products.txt");
int j = num_lines(file);
fstream in_file("products.txt",ios::in);
if(!in_file)
{
cout << "error opening file";
exit(0);
}
for(i = 0; i < h; i++)
{
in_file >> store[i].productName1;
in_file >> store[i].quantity;
in_file >> store[i].price;
}
for(i=0; i < j; i++)
{
cout << "Product Name:" << list.at(i).getProduct() << endl;
for(int k=0; k<h; k++)
{
if(list.at(i).getProduct() == store[k].productName1)
{
cout << "Quantity Purchased:" << list.at(i).getQuantity() << endl;
cout << "Price:" << store[k].price << endl;
cout << "Amount of Sale:" << store[k].price * list.at(i).getQuantity() << endl;
cout << "Quantity remaining in stock:" << store[k].quantity - list.at(i).getQuantity() << endl << endl;
}
}
}