C++ :The Fast Freight Company charges the following rates: Weight of Package (in Kilograms) Rate per 500 Miles shipped 2 Kg or less $1.10 Over 2 Kg but not more than 6 Kg $2.35 Over 6 Kg but not more than 10 Kg $3.70 Over 10 Kg but not more than 20 Kg $4.80 Write a program that asks for the weight of the package and the distance it is to be shipped, and then display the charges. Input Validation: Do not accept values of 0 or less for the weight of the package. Do not accept weights of more than 20 Kg (this is maximum weight the company will ship). Do not accept distances of less than 10 miles or more than 3,000 miles. These are company’s minimum and maximum shipping distances. The program should have the capability to process multiple set of shipping data. Use a do..while statement with the prompt message "Do you want to enter another set? (Y/N)” You will incorporate an Error trap code to validate the (Y/N) response
#include<iostream>
using namespace std;
double charge(double);
int main()
{
char choice;
int flag;
double weight,distance,charges,rate;
do
{
flag=0;
while(flag==0)
{
cout<<"enter weight of the packet:";
cin>>weight;
if(weight>0) flag=1;
}
flag=0;
while(flag==0)
{
cout<<"\nenter distance :";
cin>>distance;
if(distance>=10&&distance<=3000) flag=1;
}
rate=charge(weight);
if(distance>=10&&distance<500)
{
charges=rate;
}
else if(distance>=500&&distance<1000)
{
charges=2*rate;
}
else if(distance>=1000&&distance<1500)
{
charges=3*rate;
}
else if(distance>=2000&&distance<2500)
{
charges=4*rate;
}
else
{
charges=5*rate;
}
cout<<"\nthe chages for weight "<<weight<<" and distance "<<distance<<" is "<<charges;
cout<<"\ndou you want to continue:";
cin>>choice;
}while(choice=='Y'||choice=='y');
}
double charge(double weight)
{
if(weight<2) return 1.10;
else if(weight>=2&&weight<6) return 2.35;
else if(weight>=6&&weight<10) return 3.70;
else return 4.80;
}
Get Answers For Free
Most questions answered within 1 hours.