So im trying to create a program that will calculate a shipping cost. I'm stuck on trying to calculate the actual milage and cost.
Example being 1400 miles for a 2lb package would be $2 for every 500miles. so it would cost $6. But Im having trouble getting the program to round up the 1400 to 1500 so it charges the correct amount.
I know there would have to be a way to do this without programming all the conditions.
Also the course has not reached loops yet.
Code:
// This program will calculate the shipping charges.// The shipping rates are based on per 500 miles shipped.
// They are not pro-rated, i.e., 600 miles is the same rate as 900 miles or 1000 miles.
#include <stdio.h>
#include <stdlib.h>
main()
{
double packageWeight, packageDistance, packagePrice;
int packageDistanceMath;
printf("Enter the weight of the package: \n");
scanf_s("%lf", &packageWeight);
printf("The weight you have entered is %.2lf\n", packageWeight);
// A package that weighs less than 10lbs will cost $2
if (packageWeight <= 10 )
packagePrice = 2.00;
// A package that weighs less than or equal to 50lbs but more than 10lbs will cost $4.50
if ( packageWeight <= 50 && packageWeight > 10 )
packagePrice = 4.50;
// Do not ship packages weighing more than 50lbs
if (50 <= packageWeight){
printf("The package will not ship. \n");
system("pause");
}
printf("How far are you sending the package? \n");
scanf_s("%lf", &packageDistance);
printf("The distance you entered is %.2lf\n", packageDistance);
// 200 miles will cost the same as 500 miles
// The milage is not pro-rated
if (packageDistance < 500){
packageDistance = 1;
packagePrice = packageDistance * packagePrice;
printf("The shipping charge is %.2lf \n", packagePrice);
system("pause");
}
packageDistanceMath = (packageDistance/500);
packagePrice = packageDistanceMath * packagePrice;
printf("The shipping charge is %.2lf \n", packagePrice);
system("PAUSE");
}