jeudi 6 août 2015

if else statement outputs same value every time

I'm setting up a quote generator. I have some dropdown menus that set the values of different fields in order to calculate the price of each item based on quantity and number of color prints.

When the user selects the quantity of items, the a base price for each item is assigned to 'fieldname11'. Then depending on the base price, the rate at which the price increases from the number of color prints is assigned to 'fieldname15'. (For example, if the quantity is 6 then the base price is $3.00 and will increase by $1.00 for each color print added. However, if the quantity is 25 then the base price is $2.00 and will increase by $0.50 for each additional color.)

But not only does the price come out too high, it increases at a constant rate. Since the base price changes, I've narrowed it down to fieldname15; regardless of what value fieldname11 is, the answer always comes out to be 11. What is wrong with my else if statement?

if (fieldname11 == 3.0) {fieldname15 = 1.0;}
else if (fieldname11 == 2.0) {fieldname15 = 0.5;}
else if (fieldname11 == 1.5) {fieldname15 = 0.3;}
else if (fieldname11 == 1.25) {fieldname15 = 0.25;}
else if (fieldname11 == 1.0) {fieldname15 = 0.15;}
else if (fieldname11 == 0.9) {fieldname15 = 0.1;}
else if (fieldname11 == 0.7) {fieldname15 = 0.1;}
else if (fieldname11 == 0.6) {fieldname15 = 0.05;}
else {fieldname11 = "BADNUMBER";}

Aucun commentaire:

Enregistrer un commentaire