Guest User

Untitled

a guest
Jan 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. // YOU CAN CHANGE EACH THESE VALUES AS YOU LIKE.
  4. #define PKG_MAX_WEIGHT 85.00 // DEFINING MAXIMUM ALLOWED WEIGHT OF A PACKAGE.
  5. #define PKG_MAX_VOLUME 15.00 // DEFINING MAXIMUM ALLOWED VOLUME OF A PACKAGE.
  6.  
  7. #define COST_PER_VOLUME 2.75 // DEFINING COST PER VOLUME OF A PACKAGE.
  8. #define COST_PER_WEIGHT 6.95 // DEFINING COST PER WEIGHT OF A PACKAGE.
  9.  
  10. typedef struct // DEFINING A STRUCT FOR PACKAGE DATATYPE
  11. {
  12. double width;
  13. double height;
  14. double length;
  15. double weight;
  16. double volume;
  17. double shipping_cost;
  18. } Package;
  19.  
  20. // FUNCTION PROTOTYPES
  21. double calculate_volume(double length, double width, double height);
  22. double calculate_shipping_cost(double volume, double weight);
  23.  
  24. int main()
  25. {
  26. Package package = {};
  27.  
  28. // Prompt user for weight of package in feet
  29. puts("Please enter weight of package in pounds.");
  30. scanf("%lf", &package.weight);
  31.  
  32. // Display Error Message for overweight packages
  33. if (package.weight > PKG_MAX_WEIGHT)
  34. {
  35. printf("This package is above 85 lbs and cannot ship,\nPlease enter weight of package in pounds.");
  36. return 1;
  37. }
  38. else
  39. {
  40. // Prompt user for length of package in feet
  41. puts("Please enter length of package in feet.");
  42. scanf("%lf", &package.length);
  43.  
  44. // Prompt user for width of package in feet
  45. puts("Please enter width of package in feet.");
  46. scanf("%lf", &package.width);
  47.  
  48. // Prompt user for height of package in feet
  49. puts("Please enter height of package in feet.");
  50. scanf("%lf", &package.height);
  51.  
  52. // Calculations for Volume
  53. package.volume = calculate_volume(package.length, package.width, package.height);
  54.  
  55. if (package.volume > PKG_MAX_VOLUME)
  56. {
  57. puts("This package is above 15 cubic feet and cannot ship!");
  58. return 1;
  59. }
  60. else
  61. {
  62. // Calculations for ShippingCost
  63. package.shipping_cost = calculate_shipping_cost(package.volume, package.weight);
  64.  
  65. puts("====================================");
  66. // 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.
  67. printf(" Your package shipping details:\n\n");
  68.  
  69. printf(" Weight\t:\t%.2lf\n\n", package.weight);
  70. printf(" Length\t:\t%.2lf\n\n", package.length);
  71. printf(" Width\t:\t%.2lf\n\n", package.width);
  72. printf(" Height\t:\t%.2lf\n\n", package.height);
  73. printf(" Volume\t:\t%.2lf\n\n", package.volume);
  74.  
  75. printf(" Your total shipping cost is: %.2lf\n", package.shipping_cost);
  76. puts("=====================================");
  77. }
  78. }
  79. return 0;
  80. }
  81.  
  82. // FUNCTION IMPLIMENTATIONS
  83.  
  84. /* function for calculate the volume of the package. */
  85. double calculate_volume(double length, double width, double height)
  86. {
  87. return length * width * height;
  88. }
  89.  
  90. /* function for calculate the shipping cost of the package. */
  91. double calculate_shipping_cost(double volume, double weight)
  92. {
  93. return (volume * COST_PER_VOLUME) * (weight * COST_PER_WEIGHT);
  94. }
Add Comment
Please, Sign In to add comment