1. ## Price Calulation Method

Hi,

I created a base class which contains the product info such as name and price.

I created a derived class which inherited the base class and add 3 new data members:

string demand
string supply
double price

The question is that the demand and supply data members whose values are one of the qualitative values "low", "medium" and "high". I need to compute the product price change based on those values.

class Product
{
private:
string name;
double price;
int life;
public:
Product(string na, double pr, int li);
double pricechange();

};

class Fruitublic Product
{
private:
string demand;
string supply;
double percent;

public:
Fruit(string na, double pr, int li, string de, string su, double per):Product(na, pr, li), demand(de), supply(su), percent(per){}

double calpercent(string de, string su, double per);

};

Here is the implementation file:

Product::Product(string na, double pr, int li)
{
name = na;
price = pr;
life = li;
}

double Fruit::calpercent(string de, string su, double per)
{
demand = de;
supply = su;
percent = per;

double dd, ss; // Temp local variables.

if de = "low"
{
dd = -0.3; //Manipulated figure only
}
else if de = "medium"
{
dd = 1;
}
else if de = "high"
{
dd = 1.2;
}
else
{
cout << "Your demand input is wrong." << endl;
}

if su = "low"
{
ss = 1.3;
}
else if su = "medium"
{
ss = 1;
}
else if su = "high"
{
ss = 0.8;
}
else
{
cout << "Your supply input is wrong." << endl;
}

per = dd + ss;

return per;

}

I have not yet done the pricechange() as there are many errors in the calpercent(). I do not know how to pass the low, medium and high values to change the changing price percentage.

Anyone could give me some hints to let me rewrite the code?

Thanks a lot.

gogo

2. When testing a logical expression, always use the double equal operator:
Code:
```if de == "low"

/*  if de = "low"
the single equal sign is an assignment operator.  The
condition will always be true in this case.
*/```
It is always good practice to use parans to group conditional statements:
Code:
`if (de == "low")`
David

3. Thanks a lot.

gogo