fork download
  1. //Jacklyn Isordia CSC5 Chapter 4, P. 222, #13
  2. //
  3. /**************************************************************
  4.  *
  5.  * Calculate the charges of the fast freight shipping
  6.  * ____________________________________________________________
  7.  *
  8.  * This program asks the user to enter a weight and distance
  9.  * and then displays the charges of the fast freight shipping.
  10.  * ____________________________________________________________
  11.  * INPUT
  12.  * weight : weight of the package in kilograms
  13.  * distance : distance to ship the package in miles
  14.  *
  15.  * OUTPUT
  16.  * charges : the total shipping charge in dollars
  17.  *
  18.  **************************************************************/
  19.  
  20. #include <iostream>
  21. using namespace std;
  22.  
  23. int main() {
  24.  
  25. int weight;
  26. double distance;
  27. double charges;
  28.  
  29. cout << "Enter the weight of the package (kg): ";
  30. cin >> weight;
  31. cout << "Enter the distance of the package: ";
  32. cin >> distance;
  33.  
  34. while (weight <= 0 || weight > 20)
  35. {
  36. cout << "Invalid! Enter a weight between 1 and 20 kg: ";
  37. cin >> weight;
  38. }
  39. while (distance < 10 || distance > 3000)
  40. {
  41. cout << "Invalid! Enter a distance beteen 10 and 3000 miles: ";
  42. cin >> distance;
  43. }
  44.  
  45. if (weight <= 2)
  46. charges = (distance / 500.0) * 1.10;
  47. else if (weight <= 6)
  48. charges = (distance /500.0) * 2.20;
  49. else if (weight <= 10)
  50. charges = (distance / 500.0) * 3.70;
  51. else
  52. charges = (distance / 500.0) * 4.80;
  53.  
  54. cout << "The shipping charge is: $" << charges << endl;
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0.01s 5304KB
stdin
2
20
stdout
Enter the weight of the package (kg): Enter the distance of the package: The shipping charge is: $0.044