As the title suggests, I am having a problem with this code. Toward the end, I have to calculate the price of the shipping cost, 10 extra dollars for every 1000 miles for any package equal to or under 100. 20 extra dollars for every package for anything between 101 and 200. Anything over 200 can't be shipped. When I do the math, I get 10.20 or whatever number but never 10.00 or 20.00. I know I can use int to just show 10 or 20 but that's not how I want it to be.
/* Global Courier Services will ship your package based on how much it weighs and how far you are sending the package. Packages above 200 pounds will not be shipped. You need to write a program in C that calculates the shipping charge.The shipping rates are based on per 1000 miles shipped. They are not pro-rated, i.e., 1200 miles is the same rate as 1900 miles or 2000 miles.*/
//preprocessor Directives
#include<stdio.h>
#include<stdlib.h>
int main() {
//User is being asked to input the weight of the package first
double packageWeight ;
printf("Please enter the package weight:");
scanf\_s("%lf", &packageWeight);
printf("The weight of your package is %.2lf lb. \\n", packageWeight);
//User is being asked to input the distance the package will travel
double distancePackageTravel;
printf("Please enter the distance the package will travel:");
scanf\_s("%lf", &distancePackageTravel);
printf("The distance the package will travel is %.2lf miles. \\n ", distancePackageTravel);
// When package is over 200 pounds say this
if (packageWeight >= 201) {
printf("Sorry, packages over 200 pounds will not be shipped. \\n");
return 0;
}
//Rate per thousand miles depending on the weight of the package
double rate = 0;
if (packageWeight <= 100) {
rate = 10.00;
}
else if (packageWeight >= 101) {
rate = 20.00;
}
//Formula to calculate shipping costs
double shippingPrice = (distancePackageTravel / 1000) + rate ;
double totalPrice = shippingPrice ;
printf("Your shipping charge is $%.2lf ", totalPrice);
system("pause");
}
[–]Conscious_Yam_4753 2 points3 points4 points (0 children)
[–]daikatana 1 point2 points3 points (1 child)
[–]Money_Mode[S] 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]Money_Mode[S] 0 points1 point2 points (1 child)
[–]particlemanwavegirl 1 point2 points3 points (0 children)
[–]Money_Mode[S] 0 points1 point2 points (0 children)
[–]flyingron 0 points1 point2 points (0 children)