lundi 18 juillet 2016

allocate const value into specific condition

I'm trying to allocate certain const value into specific condition.

For instance, I've 3 const value

const double highDiscount = 0.3;
const double midDiscount = 0.2;
const double lowDiscount = 0.1;

The product with the highest cost should receive the highDiscount while the mid cost should receive the midDiscount and the lowest cost should receive the lowDiscount.

Therefore, i tried using the if-else statement to allocate the const via specific condition.

if (acost > bcost && acost > ccost)
{

    discount = highDiscount;

    if ( bcost < ccost)
    {
        discount = midDiscount;

    }
    else if ( ccost < bcost )
    {
        discount = lowDiscount;
    }
}

So my output should be something like

acost has a 30% discount

ccost has a 20% discount

bcost has a 10% discount

Unfortunately, when i compile my codes, it turns out that all a,b and c has the 10% discount instead of the allocated const value.

Am i missing out some key important points here?

Aucun commentaire:

Enregistrer un commentaire