Advertisement
khaiwen1111

jas

Aug 3rd, 2020
1,887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include<iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. void read_data(double& weight, double& distance);
  6. double find_rate(double weight, double distance);
  7. void print_charge(double weight, double distance, double charge_rate);
  8.  
  9.  
  10.  
  11. int main(void)
  12. {
  13.     double aweight, adist, arate;
  14.     read_data(aweight, adist);
  15.     arate=find_rate(aweight, adist);
  16.     print_charge(aweight, adist,arate);
  17. }
  18.  
  19. void read_data(double &weight, double &distance)
  20. {
  21.     cout << "Please enter the weight of the parcel (kg): ";
  22.     cin >> weight;
  23.     cout << "Please enter the distance to the destination (km): ";
  24.     cin >> distance;
  25. }
  26. double find_rate(double weight, double distance)
  27. {
  28.     double  rate_per_km;
  29.     if (weight<6)
  30.         if (distance < 100)
  31.         {
  32.             rate_per_km = 1.2;
  33.         }
  34.         else if (distance >= 100 && distance < 300)
  35.         {
  36.             rate_per_km = 1.8;
  37.         }
  38.         else
  39.         {
  40.             rate_per_km = 2.5;
  41.         }
  42.     else if (weight >=6 && weight <30)
  43.         if (distance < 200)
  44.         {
  45.             rate_per_km = 2.2;
  46.         }
  47.         else
  48.         {
  49.             rate_per_km = 2.5;
  50.         }
  51.     else
  52.     {
  53.         rate_per_km = 4.5;
  54.     }
  55.  
  56.     return rate_per_km;
  57.    
  58. }
  59. void print_charge(double weight, double distance, double charge_rate)
  60. {
  61.     cout << "---------------------------------------------------------\n";
  62.     cout << setw(20) << "Charge" << "\n";
  63.     cout << "WEIGHT OF THE PARCEL:\t" << setw(10) << weight<<"kg\n";
  64.     cout << "DISTANCE TO THE DESTINATION:\t" << distance<<"km\n";
  65.     cout << "\n";
  66.     cout << "The charge rate is RM " << charge_rate << " per km." << "\n";
  67.     cout << "-------------------------------------------\n";
  68.     cout << "Total delivery cost is RM " << weight*distance << ".\n";
  69.     cout << "-------------------------------------------\n";
  70. }
  71.  
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement