write c++ program The Fast Freight Shipping Company charges following rates Weig
ID: 647785 • Letter: W
Question
write c++ program
The Fast Freight Shipping Company charges following rates
Weight of Packages (pounds) Rate per 500 miles Shipped
2 => weight $1.10
2 < weight <= 6 $2.20
6 < weight <= 10 $3.70
10 < weight <= 20 $4.80
Write a C++ program that asks for the weight of the package and the distance to be shipped. Then,
compute the total charge. Charge is computed in 500 mile increments. For example, if the weight of
the package is 3 pounds and distance to travel is 680 miles, then the charge will be
$2.20 * 2 = $4.40
You might need to use the ceil() method defined the cmath library for this computation. Also, here is an example of its usage int x=640; int y = 500; double range = ceil((static_cast<double>(x)/y); cout<<range
Input validation:
Do not accept 0 or less for the weight of the package. If the weight of the package is 0 or less, display
the message
write c++ program The Fast Freight Shipping Company charges following rates Weight of Packages (pounds) Rate per 500 miles Shipped 2 => weight $1.10 2Explanation / Answer
include <iostream>
#include <math.h>
#include <math.h>
using namespace std;
int main() {
float weight,rate=500,total=0.0,dist,i=1;
cout<<"enter the weight in pound and distance in mile "<<endl;
cin>>weight;
cin>>dist;
if (weight<0)
{
cout<<"weight less than zero";
exit(EXIT_FAILURE);
}
if(weight>20)
{cout<<"weight is maximum";
exit(EXIT_FAILURE);
}
if (dist>10)
{
cout<<"dist is less";
exit(EXIT_FAILURE);
}
if(dist>3000)
{
cout<<"distance not more than 3000";
exit(EXIT_FAILURE);
}
range = ceil((static_cast<double>(dist)/rate);
if(weight<=2)
{
if(dist<=500)
{
total=1.10;
}
if(dist>500)
{
total=1.10*2;
}
}
if(weight>2 && weight<=6)
{ if(dist<=500)
{
total=2.20;
}
if(dist>500)
{
total=2*2*2;
}
}
if(weight>6 && weight<=10 )
{
if(dist<=500)
{
total=3.70;
}
if(dist>500)
{
total=3.70*2;
}
}
if(weight<=20)
{
if(dist<=500)
{
total=4.80;
}
if(dist>500)
{
total=4.80*2;
}
}
cout<<total<<endl;
// your code goes here
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.