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
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 “weight should be a greater than 0”
Do not accept more than 20 for the weight of the package. If the weight of the pages more than 20, display the message “max weight should 20”
Also, do not accept the distances of less than 10 and greater than 3000 (these are the company’s min
and max shipping distances)
This is the code I have so far. What do I need to do from here?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include<iostream>
#include<iomainp>
using namespace std;
int main()
{
const int distance_unit = 500;
double rate = 0, shippingcost;
int weight, distance
cout << setprecision(2) << fixed;
cout << "How much does the package weigh in kilograms?";
cin >> weight;
if(weight <= 0)
{
cout << "The weight should be greater than zero";
}
if (weight > 20)
{
cout << "The max weight should be 20"; }
else
cout << "How far will the package be going?";
cin >> distance;
if (distance < 10 || distance > 3000)
{
cout << "The distance you entered is not in the min and max range."; }
if (weight <= 2)
{
rate = 1.10;
}
else if (weight >2 && weight <= 6)
{
rate = 2.20;
}
else if (weight > 6 && weight <= 10)
{
rate = 3.70;
}
else
{
rate = 4.80;
}
shippingcost = distance * rate;
|