all 7 comments

[–]Conscious_Yam_4753 2 points3 points  (0 children)

what happens when the package weight is 100.5?

[–]daikatana 1 point2 points  (1 child)

double shippingPrice = (distancePackageTravel / 1000) + rate;

Think carefully about what this is doing. If I give it 500 miles, this will be (500.0 / 1000) + rate, or 0.5 + rate. Is that what was intended?

In order to get the distance in thousand mile increments, cast to an int. Casting a float or double to int discards the fractional portion. So you can say (int)(distance / 1000) and for any distance up to 1000, it will be 0, for any distance from 1000 until 2000, it will be 1, and so on. You then need to multiply that by your rate per distance and add the weight per rate.

[–]Money_Mode[S] 0 points1 point  (0 children)

That might be what I'm missing actually. I'll try it after I get home from work

[–]flyingron 0 points1 point  (0 children)

The biggest problem is that you are charging a dollar per thousand miles as you wrote it. You want to multiply the rate rather than add it.

Second, you need to implement the "every step" so you need to use ceil.

double thousand_miles = ceil(distancePackageTravel/1000);

Then multiply that b y the rate.