我正在制作一个运输计算器,如果包装重量超过50磅,则无法运送包裹。我只想在包装重量超过50磅的情况下发表声明,但无论如何都会出现。
我尝试将其作为else语句,if语句和if else语句。
main(){
double distance, weight, weightCharges, shippingCharge, distanceCharge, unableToShip;
printf ("Enter the weight of the package:\n");
scanf ("%lf", &weight);
printf ("Enter the distance your package needs to go: \n");
scanf ("%lf", &distance);
if (weight <= 10)
weightCharges = weight * 3.00;
else
if (weight <= 50)
weightCharges = weight * 5.00;
else (weight > 50);
weightCharges= 0;
if (distance > 1000)
distanceCharge = weightCharges + 10;
shippingCharge = weightCharges + distanceCharge;
unableToShip = weight > 50;
printf ("Your total cost is: %.2lf \n", shippingCharge);
printf ("We're unable to ship your package \n", unableToShip);
}
我希望第二个printf仅在我们无法发送包装时出现,但无论如何都会出现。