lundi 18 janvier 2021

If statement that gives incorrect output

This is my code:

if(weight<=5)
    cost=(2.8*weight);
if(weight<=20)
    cost=(2.8*5)+(5.2*(weight-5));
if(weight<=50)
    cost=(2.8*5)+(5.2*15)+(7*(weight-20));
if(weight>50)
    cost=(2.8*5)+(5.2*15)+(7*30)+(8.6*(weight-50));

when weight is lesser than 6.9, why is the answer all negative?

Aucun commentaire:

Enregistrer un commentaire