Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <iomanip>
- using namespace std;
- void read_data(double& weight, double& distance);
- double find_rate(double weight, double distance);
- void print_charge(double weight, double distance, double charge_rate);
- int main(void)
- {
- double aweight, adist, arate;
- read_data(aweight, adist);
- arate=find_rate(aweight, adist);
- print_charge(aweight, adist,arate);
- }
- void read_data(double &weight, double &distance)
- {
- cout << "Please enter the weight of the parcel (kg): ";
- cin >> weight;
- cout << "Please enter the distance to the destination (km): ";
- cin >> distance;
- }
- double find_rate(double weight, double distance)
- {
- double rate_per_km;
- if (weight<6)
- if (distance < 100)
- {
- rate_per_km = 1.2;
- }
- else if (distance >= 100 && distance < 300)
- {
- rate_per_km = 1.8;
- }
- else
- {
- rate_per_km = 2.5;
- }
- else if (weight >=6 && weight <30)
- if (distance < 200)
- {
- rate_per_km = 2.2;
- }
- else
- {
- rate_per_km = 2.5;
- }
- else
- {
- rate_per_km = 4.5;
- }
- return rate_per_km;
- }
- void print_charge(double weight, double distance, double charge_rate)
- {
- cout << "---------------------------------------------------------\n";
- cout << setw(20) << "Charge" << "\n";
- cout << "WEIGHT OF THE PARCEL:\t" << setw(10) << weight<<"kg\n";
- cout << "DISTANCE TO THE DESTINATION:\t" << distance<<"km\n";
- cout << "\n";
- cout << "The charge rate is RM " << charge_rate << " per km." << "\n";
- cout << "-------------------------------------------\n";
- cout << "Total delivery cost is RM " << weight*distance << ".\n";
- cout << "-------------------------------------------\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement