Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- // YOU CAN CHANGE EACH THESE VALUES AS YOU LIKE.
- #define PKG_MAX_WEIGHT 85.00 // DEFINING MAXIMUM ALLOWED WEIGHT OF A PACKAGE.
- #define PKG_MAX_VOLUME 15.00 // DEFINING MAXIMUM ALLOWED VOLUME OF A PACKAGE.
- #define COST_PER_VOLUME 2.75 // DEFINING COST PER VOLUME OF A PACKAGE.
- #define COST_PER_WEIGHT 6.95 // DEFINING COST PER WEIGHT OF A PACKAGE.
- typedef struct // DEFINING A STRUCT FOR PACKAGE DATATYPE
- {
- double width;
- double height;
- double length;
- double weight;
- double volume;
- double shipping_cost;
- } Package;
- // FUNCTION PROTOTYPES
- double calculate_volume(double length, double width, double height);
- double calculate_shipping_cost(double volume, double weight);
- int main()
- {
- Package package = {};
- // Prompt user for weight of package in feet
- puts("Please enter weight of package in pounds.");
- scanf("%lf", &package.weight);
- // Display Error Message for overweight packages
- if (package.weight > PKG_MAX_WEIGHT)
- {
- printf("This package is above 85 lbs and cannot ship,\nPlease enter weight of package in pounds.");
- return 1;
- }
- else
- {
- // Prompt user for length of package in feet
- puts("Please enter length of package in feet.");
- scanf("%lf", &package.length);
- // Prompt user for width of package in feet
- puts("Please enter width of package in feet.");
- scanf("%lf", &package.width);
- // Prompt user for height of package in feet
- puts("Please enter height of package in feet.");
- scanf("%lf", &package.height);
- // Calculations for Volume
- package.volume = calculate_volume(package.length, package.width, package.height);
- if (package.volume > PKG_MAX_VOLUME)
- {
- puts("This package is above 15 cubic feet and cannot ship!");
- return 1;
- }
- else
- {
- // Calculations for ShippingCost
- package.shipping_cost = calculate_shipping_cost(package.volume, package.weight);
- puts("====================================");
- // Display a shippingReport consisting of the width, length, height in feet, the weight of the box, volume of the box, and the cost of shipping.
- printf(" Your package shipping details:\n\n");
- printf(" Weight\t:\t%.2lf\n\n", package.weight);
- printf(" Length\t:\t%.2lf\n\n", package.length);
- printf(" Width\t:\t%.2lf\n\n", package.width);
- printf(" Height\t:\t%.2lf\n\n", package.height);
- printf(" Volume\t:\t%.2lf\n\n", package.volume);
- printf(" Your total shipping cost is: %.2lf\n", package.shipping_cost);
- puts("=====================================");
- }
- }
- return 0;
- }
- // FUNCTION IMPLIMENTATIONS
- /* function for calculate the volume of the package. */
- double calculate_volume(double length, double width, double height)
- {
- return length * width * height;
- }
- /* function for calculate the shipping cost of the package. */
- double calculate_shipping_cost(double volume, double weight)
- {
- return (volume * COST_PER_VOLUME) * (weight * COST_PER_WEIGHT);
- }
Add Comment
Please, Sign In to add comment